我几天前因为一个奇怪的问题而陷入困境,当我在iOS应用中使用GPPS身份验证时,使用GPPSignIn共享实例,homeServerAuthorizationCode为nil,并且没有错误:o我必须注销用户并重新进行身份验证才能将此代码发送到我的服务器:/
它有效,但它非常脏,而且它不能提供良好的用户体验:(
以下是我使用的代码:
- (IBAction)googleConnect:(id)sender {
[[GPPSignIn sharedInstance] authenticate];
}
- (void)finishedWithAuth:(GTMOAuth2Authentication *)auth
error:(NSError *)error {
if (!error) {
NSString *code = [GPPSignIn sharedInstance].homeServerAuthorizationCode;
NSLog(@"google code : %@", code);
if (code) {
// do my stuff with the code
} else {
[[GPPSignIn sharedInstance] signOut];
[[GPPSignIn sharedInstance] authenticate];
}
} else {
NSLog(@"%@", error);
}
}
这是GPPSignIn单例的配置。我在appDelegate中执行此操作:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
GPPSignIn *signIn = [GPPSignIn sharedInstance];
signIn.shouldFetchGooglePlusUser = YES;
signIn.clientID = googleClientID;
signIn.homeServerClientID = googleHomeClientID;
signIn.scopes = @[ kGTLAuthScopePlusLogin ];
return YES;
}