Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

google signin not calling delegate method after success

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

    [GIDSignIn sharedInstance].delegate = self;
    [GIDSignIn sharedInstance].uiDelegate = self;

-(void)signIn:(GIDSignIn *)signIn didSignInForUser:(GIDGoogleUser *)user withError:(NSError *)error{
}

not called . where is the issue not getting

when i am entering user email and password i am getting this

enter image description here

this method is called and showing error is null.

- (void)signInWillDispatch:(GIDSignIn *)signIn error:(NSError *)error {

}
like image 441
Sport Avatar asked May 23 '16 05:05

Sport


2 Answers

Add following code in your AppDelegate.m file

-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{



    return [[GIDSignIn sharedInstance] handleURL:url
                               sourceApplication:sourceApplication
                                      annotation:annotation];
    }
like image 147
Hetal Avatar answered Oct 23 '22 06:10

Hetal


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 <NSObject>        
- (void)signIn:(GIDSignIn *)signIn didSignInForUser:(GIDGoogleUser *)user withError:(NSError *)error;

@protocol GIDSignInUIDelegate <NSObject>
@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!")}
}
like image 21
Goodsquirrel Avatar answered Oct 23 '22 06:10

Goodsquirrel