ios - 谷歌登录 : Unable to disconnect iOS app

标签 ios swift google-plus-signin

我在我的 iOS 应用程序中实现了 google SignIn,并且可以首次登录到 google 帐户。但是,当我注销并尝试重新登录时,我看到的是帐户权限屏幕,如下所示,最后一个用户而不是登录屏幕。

enter image description here

下面是我用过的代码。

var signIn = GIDSignIn.sharedInstance()
signIn.delegate = self
signIn.uiDelegate = self

下面是退出和断开连接的代码

GIDSignIn.sharedInstance().signOut()
GIDSignIn.sharedInstance().disconnect()

断开连接后,我再次尝试使用以下代码登录

GIDSignIn.sharedInstance().signIn()

如何在注销和断开连接后显示登录屏幕?

最佳答案

我被困在这个问题上有一段时间了,然后我想出了一个非常 hacky 的解决方案。

GIDSignIn 帐户列表似乎使用的是 Safari Web View,因此其帐户记录使用的是 cookie/本地存储,并且独立于 iOS Keychain(和 OAuth token )。

当用户在我的应用程序上点击注销时,我会像这样打开一个 SFSafariViewController:

import SafariServices

class MyViewController: SFSafariViewControllerDelegate {
...

在您的按钮操作中(或您要注销用户的位置):

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 委托(delegate)方法并关闭 View Controller ,如下所示:

func safariViewController(_ controller: SFSafariViewController, didCompleteInitialLoad didLoadSuccessfully: Bool) {
    controller.dismiss(animated: false) {
        //Switch view controllers
    }
}

这似乎是我能想到的唯一方法。

关于ios - 谷歌登录 : Unable to disconnect iOS app,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39129888/

相关文章:

swift - 如何使用超过 2 个参数在 Swift 中调用选择器

ios - Swift - 两个不同类的相同协议(protocol)

ios - 如何在 Swift 中添加带有 GIF 背景的 UIButtons?

angular - ionic 原生谷歌加登录中的错误10

iphone - 如何更改 uinavigationbar 后退按钮文本

ios - Expo.Notifications.addListener() 未触发(iOS 独立应用程序)

ios - iPhone 查看照片 - 向任意方向滑动

android - 从自定义 Fragment 调用 DialogFragment,然后设置其属性

android - 无法使用 SmartLock 保存 IdentityProviders.GOOGLE 凭据

iphone - 椭圆的周围区域是黑色的。为什么?