gpt4 book ai didi

ios - 为什么我的谷歌登录在我成功登录后不显示帐户选择?

转载 作者:搜寻专家 更新时间:2023-11-01 06:13:46 26 4
gpt4 key购买 nike

我已在使用 Firebase 的应用中成功实现了 google 登录。当我第一次使用谷歌账户登录时,会出现一个对话框来选择谷歌账户。

但是在我成功登录然后注销后,当我尝试再次登录时,选择谷歌帐户的对话框不会再出现,它只是直接将我带到主菜单。

每次用户通过 google 登录时,我都希望始终显示该对话框。这是我在具有谷歌登录按钮的 VC 中使用的代码

import UIKit
import Firebase
import GoogleSignIn
import SVProgressHUD

class AuthenticationVC : UIViewController, GIDSignInUIDelegate, GIDSignInDelegate {

var userID : String?

override func viewDidLoad() {
super.viewDidLoad()

// delegate declaration
GIDSignIn.sharedInstance().uiDelegate = self

// For Google SignIn Using Firebase
GIDSignIn.sharedInstance().clientID = FirebaseApp.app()?.options.clientID
GIDSignIn.sharedInstance().delegate = self
}




@IBAction func googleButtonDidPressed(_ sender: Any) {
GIDSignIn.sharedInstance().signIn()
}



}


extension AuthenticationVC {

// MARK: - Firebase Google Sign In Authentication Methods
// The methods below will be triggered if the user want to login via google account

@available(iOS 9.0, *)
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
return GIDSignIn.sharedInstance().handle(url,sourceApplication:options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String, annotation: [:])
}



func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
return GIDSignIn.sharedInstance().handle(url,sourceApplication: sourceApplication,annotation: annotation)
}


func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error?) {

SVProgressHUD.show(withStatus: "Harap Tunggu")

if let error = error {
SVProgressHUD.dismiss()
print("failed to login into google")
print("\(error.localizedDescription)")
return
}
print("user successfully signin into google")

guard let authentication = user.authentication else {
SVProgressHUD.dismiss()
return
}

let credential = GoogleAuthProvider.credential(withIDToken: authentication.idToken,
accessToken: authentication.accessToken)

Auth.auth().signIn(with: credential) { (user, error) in
if let error = error {
SVProgressHUD.dismiss()
print("failed to create firebase user using google account")
print("\(error.localizedDescription)")
return
}

print("user successfully logged into firebase")

guard let userKMFromGoogleSignIn = user else {
SVProgressHUD.dismiss()
return

}

self.userID = userKMFromGoogleSignIn.uid


// if the user sign Up for the very first time using google account, then user Basic Information stored in the firestore will be nil, therefore we create user basic data to firestore

// if user has signed up before via google account, then directly send to mainTabBar (it means he/she has picked a city before), otherwise pickCity first

self.checkUserBasicInformationInFirestore(userKMFromGoogleSignIn)


}

}

func sign(_ signIn: GIDSignIn!, didDisconnectWith user: GIDGoogleUser!, withError error: Error!) {
// Perform any operations when the user disconnects from app here.
// ...
}


}

这是用户点击注销按钮时的代码

  @IBAction func logOutButtonDidPressed(_ sender: Any) {
do {
try Auth.auth().signOut()
print("User Did Log Out")
performSegue(withIdentifier: "Back", sender: nil)
} catch {
showAlert(alertTitle: "Sorry", alertMessage: "\(error)", actionTitle: "Back")
}
}

我该怎么办?

最佳答案

尝试在进入 View Controller 时注销。注销将使当前 token 过期,您将被要求使用帐户列表再次登录。

override func viewDidLoad() {
//Configure and set delegate
...
GIDSignIn.sharedInstance().signOut()
GIDSignIn.sharedInstance().disconnect()
}

@IBAction func logOutButtonPressed(_ sender: Any) {
GIDSignIn.sharedInstance().signOut()
GIDSignIn.sharedInstance().disconnect()
}

关于ios - 为什么我的谷歌登录在我成功登录后不显示帐户选择?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49827821/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com