google signin not calling delegate method after success

后端 未结 5 1146
有刺的猬
有刺的猬 2021-01-18 20:06

i am using google sdk for google signin but after entering the email and password

in viewDidLoad i have added delegate

//set Google sign In delegates

5条回答
  •  余生分开走
    2021-01-18 20:33

    The method that get's called is called on GIDSignInUiDelegate, while the method that is not called is called on the GIDSignInDelegate after login. Here's what the GIDSignIn header file says:

    @protocol GIDSignInDelegate         
    - (void)signIn:(GIDSignIn *)signIn didSignInForUser:(GIDGoogleUser *)user withError:(NSError *)error;
    
    @protocol GIDSignInUIDelegate 
    @optional
    - (void)signInWillDispatch:(GIDSignIn *)signIn error:(NSError *)error;
    

    Since you have set both the uiDelegate and the delegate to your UIViewController instance, both methods should get called.

    When I encountered the same problem, my mistake was, that I also set the AppDelegate to be the GIDSignInDelegate causing confusion for hours! So my advice: double check if your ViewController still is the delegate of GIDSignIn.sharedInstance when returning from sign in. E.g. set a breakpoint in the callback that get's called:

    - (void)signInWillDispatch:(GIDSignIn *)signIn error:(NSError *)error {
        if (GIDSignIn.delegate != self) {NSLog("gotcha!")}
    }
    

提交回复
热议问题