2016-06-21 20 views
14

因此,我的應用可以選擇使用Google登錄。點擊Google提供的按鈕後,即會打開Web視圖並讓用戶輸入其憑據。在允許應用程序訪問他們的信息之後,應用程序將簽名用戶並將SignInViewController更改爲TabBarController(他們現在可以相互交互)。如何在經過身份驗證後退出Google

當用戶按下「註銷」按鈕時,它們會像您期望的那樣指向登錄屏幕。但奇怪的是,如果用戶再次按下谷歌按鈕,他們會自動登錄,根本沒有進一步的身份驗證,並且沒有選擇刪除他們的帳戶。他們是否可以清除Google帳戶憑據以保護用戶免遭意外盜竊?

登錄功能:

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

登出功能:

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)") 
    } 
} 
+0

你試過GIDSignIn.sharedInstance() .signOut() –

+0

謝謝,這工作! – About7Deaths

+0

不客氣 –

回答

26

斯威夫特

嘗試GIDSignIn.sharedInstance().signOut()

的Objective - C

[[GIDSignIn sharedInstance] signOut];