我已经设置了clientID,范围,然后在MyViewController上单击按钮,我从LoginCLass调用方法登录,但是在[signIn authenticate]之后,委托实现finishedWithAuth没有被调用.我已将.h文件设置为 - (NSError *) login{ N
- (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);
}
而且在AppDelegate中我正在添加代码
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [GPPURLHandler handleURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
我已检查要指定的软件包ID和URL类型,它们与Google API访问中的软件包ID相同.
这些方法在LoginClass中,在MyViewController类中使用.
当我将finishedWithAuth委托设置为MyViewController时,通过将其设置为GPPSignInDelegate,代码运行正常.但是,我想在LoginClass中使用它.
任何想法,我哪里错了?
由于您的LoginClass是一个Swift类,因此修复它是使它成为NSObject的子类.我遇到了同样的问题:当我尝试将委托设置为不是NSObject的子类的类时,分配失败并且委托仍为零.当我将NSObject作为超类添加时,赋值按预期工作.
