如何自定义Google+登录按钮ios?
有没有办法直接登录而无需点击Google+登录按钮?
答案 0 :(得分:12)
是的,有办法直接登录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是您从谷歌注册的应用中获取的应用客户端ID。当然,您需要设置委托(GPPSignInDelegate
)。