簡體   English   中英

'AppDelegate'不符合協議'GIDSignInDelegate'

[英]'AppDelegate' does not conform to protocol 'GIDSignInDelegate'

我正在嘗試在swift-3中實現Google Signin,但遇到一個非常奇怪的錯誤,我正在點擊鏈接https://developers.google.com/identity/sign-in/ios/sign-in?ver=swift 但是,每次執行一次又一次時,我都會看到此錯誤。 我在橋接頭中添加了以下內容。

#import <Google/SignIn.h>

我已經安裝了Pod GoogleSignin Pod'Google pod 'Google/SignIn'

這是我的AppDelegate文件代碼

    class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {   //<--Here it gives the error
        //Method implemented but giving the error
        func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
        //TODO
        }
    }

'AppDelegate'不符合協議'GIDSignInDelegate'

我試過重新安裝吊艙

我曾嘗試清潔和其他東西,但沒有發現幫助。

我剛剛花了3個小時。 您需要實現的正確簽名是:

func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!)

但是- 檢查您是否沒有在應用程序 (或其他類GIDSignInGIDGoogleUser )中覆蓋Error的定義 我的應用程序中有一個自定義的Error類,它已覆蓋默認的Error類。 重命名Error類后,問題消失了。

斯威夫特的編譯器是不是非常有幫助這里,因為它顯示的類型Error在錯誤信息這兩種情況下,而不是指示他們都表示不同的Error類型。

本課的目的是不使用Foundation中已經為我的班級使用的名稱。

您需要在appdelegate中添加以下兩種方法

func sign(_ signIn: GIDSignIn!, didDisconnectWith user: GIDGoogleUser!, withError error: Error!) {

}

func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {

}

您必須實現GIDSignInDelegate所有必需方法才能消除此錯誤。 因此,請檢查GIDSignInDelegate協議中的方法列表,並在AppDelegate類中實現。

並在didFinsishLaunchingOption方法中將委托設置為:

GIDSignIn.sharedInstance().delegate = self

好吧,這是一個非常愚蠢的錯誤,我的代碼中有一個名為Error的自定義類,由於GidSignInDelegate方法無法識別要引用的錯誤類,因此引起了問題。 如果您犯了同樣的愚蠢錯誤,請尋找答案的任何人進行交叉檢查。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM