如何在经过身份validation后退出Google

因此,我的应用可以选择使用Google登录。 单击Google提供的按钮后,将打开Web视图并让用户输入其凭据。 在允许应用访问他们的信息后,应用程序然后签署用户并将SignInViewController更改为TabBarController(他们现在可以相应地进行交互)。

当用户按下“注销”按钮时,他们将按照人们的预期被定向到登录屏幕。 但奇怪的是,如果用户再次按下谷歌按钮,他们会自动登录,根本不需要进一步的身份validation,也无法删除他们的帐户。 他们是否有办法清除谷歌帐户凭据以保护用户免遭意外盗窃?

登录function:

func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!, withError error: NSError!) { if let error = error { print(error.localizedDescription) return } let authentication = user.authentication let credential = FIRGoogleAuthProvider.credentialWithIDToken(authentication.idToken, accessToken: authentication.accessToken) FIRAuth.auth()?.signInWithCredential(credential) { (user, error) in // ... SignInViewController().signedIn(user) } // ... } 

退出function:

 func signOutOverride() { do { try! FIRAuth.auth()!.signOut() CredentialState.sharedInstance.signedIn = false // Set the view to the login screen after signing out let storyboard = UIStoryboard(name: "SignIn", bundle: nil) let loginVC = storyboard.instantiateViewControllerWithIdentifier("SignInVC") as! SignInViewController let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate appDelegate.window?.rootViewController = loginVC } catch let signOutError as NSError { print ("Error signing out: \(signOutError)") } } 

迅速

尝试GIDSignIn.sharedInstance().signOut()

目标 – c

 [[GIDSignIn sharedInstance] signOut]; 

是的,就像@Rahul所说,以下代码是正确的方式。

 GIDSignIn.sharedInstance().signOut() 

https://developers.google.com/identity/sign-in/ios/sign-in?ver=swift#sign_out_the_user