'AppDelegate'不符合协议'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类后,问题就消失了。

Swift编译器在这里并不是很有帮助,因为它在错误信息中显示了两种情况下的Errortypes,而没有指出它们都是不同的Errortypes。

这个教训是不要使用已经用于基础课程的名字。

您需要在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方法无法识别引用哪个错误类。 任何寻找答案,如果你犯了同样的愚蠢的错误,请交叉检查。