Google SignIn: Unable to disconnect iOS app

我只是一个虾纸丫 提交于 2019-12-07 04:16:54

问题


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.

Below is the code I've used.

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?


回答1:


I was stuck on this for a while and I came up with a pretty hacky solution.

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).

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)

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.



来源:https://stackoverflow.com/questions/39129888/google-signin-unable-to-disconnect-ios-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!