finishedWithAuth not called after authenticate method

前端 未结 5 1063
天涯浪人
天涯浪人 2021-01-20 05:12

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]

相关标签:
5条回答
  • 2021-01-20 05:52

    You Can use

    if (![signIn trySilentAuthentication])
            [signIn authenticate];
    

    Follow this link for more detail
    trySilentAuthentication without Google+ button

    0 讨论(0)
  • 2021-01-20 05:55

    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

    0 讨论(0)
  • 2021-01-20 05:58

    Here is the simple solution for this.

    func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
        if (url.absoluteString.range(of: "oauth2callback") != nil) {
           GPPSignIn.sharedInstance().handle(url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String, annotation: nil)
        }
       return false
    }
    
    0 讨论(0)
  • 2021-01-20 06:09

    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.

    0 讨论(0)
  • 2021-01-20 06:11

    This happened to me too in my apps running iOS 8. What did it for me was to set the clientId in the AppDelegate as soon as the app launched, and not in the viewDidLoad method of my UIViewController class as indicated in the Google+ Sign-in for iOS example in the following URL: https://developers.google.com/+/mobile/ios/sign-in

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    /
    //Google+
    // Set app's client ID for |GPPSignIn| and |GPPShare|.
    [GPPSignIn sharedInstance].clientID = @"xxxxxx.......apps.googleusercontent.com";
    
    ...
    
    return YES;
    
    }
    

    So, in your UIViewController class the sign-in method should be:

     - (void)viewDidLoad {
    [super viewDidLoad];
    
    //Google+ for Logging in the user again if the app has been authorized
    signIn = [GPPSignIn sharedInstance];
    signIn.shouldFetchGooglePlusUser = YES;
    signIn.shouldFetchGoogleUserID = YES;
    signIn.shouldFetchGoogleUserEmail = YES;
    signIn.scopes = @[ kGTLAuthScopePlusLogin ];
    signIn.delegate = self;
    [signIn trySilentAuthentication];
    
    ...
    }
    
    0 讨论(0)
提交回复
热议问题