如何自定义Google+登录按钮ios?
有没有办法直接登录而无需点击Google+登录按钮?
是的,有办法直接登录Google+
.
在AppDelegate
,添加这个,
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { return [GPPURLHandler handleURL:url sourceApplication:sourceApplication annotation:annotation]; }
并且您的登录视图控制器应该添加此代码部分.
- (void)loginWithGooglePlus { [GPPSignIn sharedInstance].clientID = kClientID; [GPPSignIn sharedInstance].scopes= [NSArray arrayWithObjects:kGTLAuthScopePlusLogin, nil]; [GPPSignIn sharedInstance].shouldFetchGoogleUserID=YES; [GPPSignIn sharedInstance].shouldFetchGoogleUserEmail=YES; [GPPSignIn sharedInstance].delegate=self; [[GPPSignIn sharedInstance] authenticate]; } - (void)finishedWithAuth:(GTMOAuth2Authentication *)auth error:(NSError *)error { if (!error) { NSLog(@"Google+ login successful"); } else { NSLog(@"Error: %@", error); } }
kClientID是您从Google注册的应用中获取的应用客户端ID.当然你需要设置delegate(GPPSignInDelegate
).