我正在尝试实施一个退出按钮,根据当前用户类型(Facebook与Google),它将根据当前用户的登录类型退出。我可以使用不同的帐户登录但是想要根据登录的帐户类型退出功能是有条件的...提前感谢!
// sign out functions
func handleSignOut() {
// facebook sign out
UserDefaults.standard.setIsLoggedIn(value: false)
FBSDKLoginManager().logOut()
print("did log out of facebook...")
// google signout
let firebaseAuth = FIRAuth.auth()
do {
try firebaseAuth?.signOut()
} catch let signOutError as NSError {
print ("Error signing out: %@", signOutError)
}
let loginController = LoginController()
present(loginController, animated: true, completion: nil)
}
func loginButtonDidLogOut(_ loginButton: FBSDKLoginButton!) {
do {
try FIRAuth.auth()!.signOut()
} catch let logoutError {
print(logoutError)
}
}
答案 0 :(得分:0)
尝试在UserDefaults
用户登录的帐户中存储(例如,使用字符串值"google"
或"facebook"
存储"帐户"密钥)。
然后,在您的退出方法handleSignOut() {...}
中,测试该值,即
let at = (UserDefaults.getAccountType())
if at == "google" {
handleGoogle()
} else if at == "facebook" {
handleFacebook()
}
*为UserDefaults.getAccountType