【发布时间】:2014-08-16 04:56:15
【问题描述】:
我有一个带有 IBAction 的简单 iOS 应用程序。但是,完成处理程序代码没有运行,我无法弄清楚它为什么没有运行。这是我的代码:
-(IBAction)didTapSignIn:(id)sender {
void (^handler)(id, id, id) = ^(GTMOAuth2ViewControllerTouch *viewController, GTMOAuth2Authentication *auth, NSError *error) {
NSLog(@"TEST 2");
[self dismissViewControllerAnimated:YES completion:^{
NSLog(@"AC: %@ \nRT: %@", auth.accessToken, auth.refreshToken);
NSLog(@"AC TOKEN: %@", [GPPSignIn sharedInstance].authentication.accessToken);
NSLog(@"RF TOKEN: %@", [GPPSignIn sharedInstance].authentication.refreshToken);
NSLog(@"KEYCHAIN: %@", [GPPSignIn sharedInstance].keychainName);
}];
NSLog(@"AC: %@ \nRT: %@", auth.accessToken, auth.refreshToken);
NSLog(@"AC TOKEN: %@", [GPPSignIn sharedInstance].authentication.accessToken);
NSLog(@"RF TOKEN: %@", [GPPSignIn sharedInstance].authentication.refreshToken);
NSLog(@"KEYCHAIN: %@", [GPPSignIn sharedInstance].keychainName);
/*
if (error) {
NSLog(@"%@", error);
return;
}
else {
BOOL signedIn = [[GPPSignIn sharedInstance] trySilentAuthentication];
if (!signedIn) {
NSLog(@"Sign In failed");
}
}*/
};
GTMOAuth2ViewControllerTouch *controller = [GTMOAuth2ViewControllerTouch controllerWithScope:@"https://www.googleapis.com/auth/plus.login" clientID:[GPPSignIn sharedInstance].clientID clientSecret:nil keychainItemName:[GPPSignIn sharedInstance].keychainName completionHandler:handler];
NSLog(@"TEST 1");
[self presentViewController:controller animated:YES completion:nil];
NSLog(@"TEST 3");
}
我做错了什么?它应该运行,但它没有。
感谢您抽出宝贵时间,丹。
【问题讨论】:
-
GTMOauth2ViewControllerTouch 中的completionHandler 做了什么?如果你在展示你的控制器后想要完成处理程序,你应该调用 [self presentViewController:controller animated:YES completion:handler];
标签: ios objective-c cocoa-touch methods completionhandler