简体   繁体   English

'AppDelegate'不符合协议'GIDSignInDelegate'

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

I am Trying to implement Google Signin in swift-3 but I am having a very strange error I am following the link https://developers.google.com/identity/sign-in/ios/sign-in?ver=swift . 我正在尝试在swift-3中实现Google Signin,但遇到一个非常奇怪的错误,我正在点击链接https://developers.google.com/identity/sign-in/ios/sign-in?ver=swift But I see this error everytime I do Implement it again and again. 但是,每次执行一次又一次时,我都会看到此错误。 I have added the following in bridging header. 我在桥接头中添加了以下内容。

#import <Google/SignIn.h>

I have installed the pod GoogleSignin pod 'Google/SignIn' 我已经安装了Pod GoogleSignin Pod'Google pod 'Google/SignIn'

This is my AppDelegate File code 这是我的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' does not conform to protocol 'GIDSignInDelegate' 'AppDelegate'不符合协议'GIDSignInDelegate'

I 've tried reinstalling pods 我试过重新安装吊舱

I've tried cleaning and other things but nope noting helped. 我曾尝试清洁和其他东西,但没有发现帮助。

I just spent 3 hours on this. 我刚刚花了3个小时。 The correct signature you need to implement is : 您需要实现的正确签名是:

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

But - check whether you are not overriding the definition of Error in your app (or the other classes GIDSignIn , GIDGoogleUser ). 但是- 检查您是否没有在应用程序 (或其他类GIDSignInGIDGoogleUser )中覆盖Error的定义 I had a custom Error class in my app which has overridden the default Error class. 我的应用程序中有一个自定义的Error类,它已覆盖默认的Error类。 After I renamed my Error class, the problem went away. 重命名Error类后,问题消失了。

Swift compiler was not very helpful here, because it displayed the type as Error for both cases in the error message, while not indicating they both mean different Error types. 斯威夫特的编译器是不是非常有帮助这里,因为它显示的类型Error在错误信息这两种情况下,而不是指示他们都表示不同的Error类型。

The lesson is to not use names already used in Foundation for my classes. 本课的目的是不使用Foundation中已经为我的班级使用的名称。

you need to add following two method in appdelegate 您需要在appdelegate中添加以下两种方法

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

}

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

}

You must have to implement all required method of GIDSignInDelegate to remove this error. 您必须实现GIDSignInDelegate所有必需方法才能消除此错误。 So check the list of method in GIDSignInDelegate protocol and implement in the AppDelegate class. 因此,请检查GIDSignInDelegate协议中的方法列表,并在AppDelegate类中实现。

And in didFinsishLaunchingOption method set the delegate as: 并在didFinsishLaunchingOption方法中将委托设置为:

GIDSignIn.sharedInstance().delegate = self

Well it was a very silly mistake, I had a custom class named Error in my code and It caused the issue as the GidSignInDelegate method was not able to recognize which error class to refer to. 好吧,这是一个非常愚蠢的错误,我的代码中有一个名为Error的自定义类,由于GidSignInDelegate方法无法识别要引用的错误类,因此引起了问题。 Anyone looking for the answer please cross check it if you have made the same silly mistake. 如果您犯了同样的愚蠢错误,请寻找答案的任何人进行交叉检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM