xcode 如何从 google plus GPPSignIn 登出?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19247807/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 04:03:13  来源:igfitidea点击:

How to log out from google plus GPPSignIn?

iosxcodegoogle-pluslogout

提问by user2230971

In my app I have a option to login to the app using google plus. Login is working fine. I am not able to logout from google+. When ever I click on login button it's not showing login page its redirecting to authentication dialog page.

在我的应用程序中,我可以选择使用 google plus 登录该应用程序。登录工作正常。我无法从 google+ 注销。当我点击登录按钮时,它不会显示登录页面,而是重定向到身份验证对话框页面。

My code is:

我的代码是:

To login

登录

GPPSignIn *signIn = [GPPSignIn sharedInstance];
signIn.shouldFetchGooglePlusUser = YES;
signIn.shouldFetchGoogleUserEmail = YES;  
signIn.shouldFetchGoogleUserID= YES;

signIn.clientID = kClientId;
signIn.scopes = [NSArray arrayWithObjects:kGTLAuthScopePlusLogin,nil];
signIn.delegate = self;

To logout

登出

- (IBAction)Logout:(id)sender {
[[GPPSignIn sharedInstance] signOut];
[[GPPSignIn sharedInstance] disconnect];
}

回答by Revanth

Take GPPSignIn *signIn globally and add the following code in your Logout button action

全局使用 GPPSignIn *signIn 并在您的注销按钮操作中添加以下代码

[signIn signOut];

回答by Daniel Galasko

The documentationon [GPPSignIn disconnect]explicitly states

有关明确说明的文档[GPPSignIn disconnect]

"If the operation succeeds, the OAuth 2.0 token is also removed from keychain. The token is needed to disconnect so do not call signOut if disconnect is to be called."

“如果操作成功,OAuth 2.0 令牌也会从钥匙串中删除。断开连接需要令牌,因此如果要调用断开连接,请不要调用 signOut。”

@Revanth is correct, you only need to call signOut (Although the unfortunate naming of his variable makes the readability confusing).

@Revanth 是正确的,您只需要调用 signOut (尽管不幸的变量命名使可读性变得混乱)。

Remember: signing out is different to disconnecting. Upon signing out you don't need to delete the users information. Google support users having multiple accounts so it could be that the user is simply signing out so they can sign in with a related account.

请记住:退出与断开连接不同。注销后,您无需删除用户信息。Google 支持拥有多个帐户的用户,因此用户可能只是退出,以便他们可以使用相关帐户登录。

Disconnection on the other hand is destructive and you should remove all the users information from the server and on their next sign in they would have to grant your app permissions again.

另一方面,断开连接是破坏性的,您应该从服务器中删除所有用户信息,并且在他们下次登录时,他们必须再次授予您的应用程序权限。

Also, your App must include the ability to perform the following: (See the rules)

此外,您的应用程序必须包括执行以下操作的能力:(请参阅规则

Know if they are connected to a Google account, and if so to which account.

Disconnect the application from their Google account(s).

Sign out of your application.

了解他们是否与 Google 帐户相关联,如果是,则与哪个帐户相关联。

断开应用程序与其 Google 帐户的连接。

退出您的应用程序。