Google登录:无法断开iOS应用的连接 [英] Google SignIn: Unable to disconnect iOS app
问题描述
我已经在我的iOS应用中实现了google SignIn,并且可以首次登录google帐户.但是,当我注销并尝试重新登录时,将显示如下所示的帐户权限"屏幕,显示的是最后一个用户,而不是登录"屏幕.
I have implemented google SignIn in my iOS app and can login to google account for the first time. But when I logout and try to log back in, I get Account Permission screen as shown below with last user instead of SignIn screen.
下面是我使用的代码.
var signIn = GIDSignIn.sharedInstance()
signIn.delegate = self
signIn.uiDelegate = self
以下是退出&的代码断开连接
Below is code to sign out & disconnect
GIDSignIn.sharedInstance().signOut()
GIDSignIn.sharedInstance().disconnect()
断开连接后,我再次尝试使用以下代码登录
After disconnecting, I again try to SignIn using below code
GIDSignIn.sharedInstance().signIn()
退出并登录后如何显示登录屏幕?断开连接吗?
How can I display login screen after Signing out & Disconnecting?
推荐答案
我在此问题上停留了一段时间,然后想出了一个非常hacky的解决方案.
I was stuck on this for a while and I came up with a pretty hacky solution.
GIDSignIn帐户列表似乎使用的是Safari Web View,因此其帐户记录使用的是cookie/本地存储,并且独立于iOS钥匙串(和OAuth令牌).
It seems the GIDSignIn account listing is using a Safari Web View, so its record of the accounts is using cookies/local storage and is independent of the iOS Keychain (and OAuth tokens).
当用户在我的应用程序上单击注销时,我将像这样打开SFSafariViewController:
When a user hits logout on my app I'm opening a SFSafariViewController like so:
import SafariServices
class MyViewController: SFSafariViewControllerDelegate {
...
在按钮操作内(或您要注销用户的位置):
inside your button action (or where you want to log the user out):
let logoutUrl = URL(string: "https://www.google.com/accounts/Logout")!
let logoutViewController = SFSafariViewController.init(url: logoutUrl)
logoutViewController.delegate = self
self.present(logoutViewController, animated: true, completion: nil)
在其中实现didCompleteInitialLoad
委托方法并关闭视图控制器,如下所示:
where you implement the didCompleteInitialLoad
delegate method and dismiss your view controller like the following:
func safariViewController(_ controller: SFSafariViewController, didCompleteInitialLoad didLoadSuccessfully: Bool) {
controller.dismiss(animated: false) {
//Switch view controllers
}
}
这似乎是我找出的唯一方法.
This seems to be the only way I can figure out.
这篇关于Google登录:无法断开iOS应用的连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!