FinishedWithAuth not called after authentication method

I already set the client identifier, the scope, and then clicked on the mouse in MyViewController, I call the login method from LoginCLass, which works, but after [signIn authenticate], the delegate implementation is completedWithAuth does not receive the call. I installed the .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);
}  

as well as in appdelegate i am adding code

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    return [GPPURLHandler handleURL:url
                  sourceApplication:sourceApplication
                         annotation:annotation];
}

I checked the package identifier and the types of URLs to be specified, they are set in the same way as the package identifier from accessing the Google APIs.

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

When I set the finishedWithAuth delegate to MyViewController, setting it as GPPSignInDelegate, the code works fine. But I want to use it from LoginClass.

Any idea where I'm wrong?

+3
5

LoginClass Swift, NSObject.

: , NSObject, , . NSObject , , .

+3

, GPPSignIn Safari .

:

GPPSignIn *signIn = [GPPSignIn sharedInstance];

. :

@implementation LoginClass {
  GPPSignIn *signIn;
}

+2

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


trySilentAuthentication Google+

+2

iOS 8. clientId AppDelegate , viewDidLoad UIViewController, Google+ iOS URL-: https://developers.google.com/+/mobile/ios/sign-in

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

...

return YES;

}

, UIViewController :

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

.

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

All Articles