简体   繁体   中英

'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 . 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'

This is my AppDelegate File code

    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'

I 've tried reinstalling pods

I've tried cleaning and other things but nope noting helped.

I just spent 3 hours on this. 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 ). I had a custom Error class in my app which has overridden the default Error class. After I renamed my Error class, the problem went away.

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.

The lesson is to not use names already used in Foundation for my classes.

you need to add following two method in 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. So check the list of method in GIDSignInDelegate protocol and implement in the AppDelegate class.

And in didFinsishLaunchingOption method set the delegate as:

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. Anyone looking for the answer please cross check it if you have made the same silly mistake.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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