验证方法后未调用finishWithAuth [英] finishedWithAuth not called after authenticate method

查看:110
本文介绍了验证方法后未调用finishWithAuth的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了clientID,作用域,然后在MyViewController上单击按钮,我从LoginCLass调用方法登录,该方法有效,但是在[signIn authenticate]之后,未调用委托实现finishWithAuth.我已经设置了.h文件

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);
}  

在AppDelegate中,我还要添加代码

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];
}

我已经检查了要指定的捆绑包ID和URL类型,它们的设置与Google API访问中的捆绑包ID相同.

I have checked the bundle ID and URL Types to be specified,they are set same as bundle ID from Google API access.

这些方法在LoginClass中,在MyViewController类中使用.

These methods are in LoginClass which are used in MyViewController class.

当我将finishWithAuth委托设置为MyViewController时,通过将其设置为GPPSignInDelegate,代码可以正常运行.但是,我想从LoginClass中使用它.

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 ??

推荐答案

由于LoginClass是Swift类,因此解决方法是使其成为NSObject的子类.

Since your LoginClass is a Swift class, the fix is to make it a subclass of NSObject.

我遇到了同样的问题:当我尝试将委托设置为不是NSObject子类的类时,分配失败并且委托保持为零.当我将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.

这篇关于验证方法后未调用finishWithAuth的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆