I have already set the clientID ,scope and then on button click in MyViewController ,i am calling method login from LoginCLass which works but after [signIn authenticate] ,the delegate implementation finishedWithAuth is not getting called.I have set .h file as
- (NSError *) login
{
NSLog(@"In login :%@ %@ %@",kClientId,scopes,actions);
if(!kClientId|| !scopes)
{
NSLog(@"Either client ID Or scope is not specified!! ");
NSError *err=[[NSError alloc]initWithDomain:@"Scope not specified" code:0 userInfo:nil];
return err;
}
else
{
NSLog(@"Client ID and Scope are set.");
GPPSignIn *signIn = [GPPSignIn sharedInstance];
signIn.delegate = self;
signIn.shouldFetchGooglePlusUser = YES;
[signIn authenticate];
[signIn trySilentAuthentication];
return nil;
}
}
- (void)finishedWithAuth:(GTMOAuth2Authentication *)auth error:(NSError *)error
{
NSLog(@"Received error %@ and auth object %@",error, auth);
}
and also in AppDelegate i am adding the code
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [GPPURLHandler handleURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
I have checked the bundle ID and URL Types to be specified,they are set same as bundle ID from Google API access.
These methods are in LoginClass which are used in MyViewController class.
When i set the finishedWithAuth delegate to MyViewController ,by setting it as GPPSignInDelegate, the code runs fine.But, i want to use it from LoginClass.
Any idea , where am i going wrong ??
Since your LoginClass is a Swift class, the fix is to make it a subclass of NSObject.
I had the same issue: when I tried to set the delegate to a class that was not a subclass of NSObject, the assignment failed and the delegate remained nil. When I added NSObject as a superclass, the assignment worked as expected.
The problem seems to be where an instance of the GPPSignIn is not persisted between leaving the app to load Safari and coming back to your app.
Currently in your login method you have:
GPPSignIn *signIn = [GPPSignIn sharedInstance];
so this is a local instance variable. Try moving this to the class level:
@implementation LoginClass {
GPPSignIn *signIn;
}
then use that in your login method
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With