gpt4 book ai didi

swift - 取消 Facebook 身份验证时,(快速)项目崩溃

转载 作者:行者123 更新时间:2023-11-28 05:58:38 25 4
gpt4 key购买 nike

我的项目使用 Firebase 和 Facebook 身份验证。它工作正常,但是当我选择取消 Facebook 身份验证时(我第一次获取 uid 时)项目崩溃了。这是我使用的方法:

   func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!) {
let credential = FacebookAuthProvider.credential(withAccessToken: FBSDKAccessToken.current().tokenString)
Auth.auth().signInAndRetrieveData(with: credential) { (user, error) in
// [START_EXCLUDE]

if let error = error {
print(error.localizedDescription)
return
}
self.uid = Auth.auth().currentUser?.uid

self.firstFetch()


// [END_EXCLUDE]
}
print("logged in")
}

谁能帮帮我,好吗?

最佳答案

好吧,这个函数的整个实现是错误的,因为无论是否通过身份验证,它都在获取用户。这是我写的新方法:

func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: 

FBSDKLoginManagerLoginResult!, error: Error!) {
if error != nil {
print("look a at your.. errm.. code, please", error.localizedDescription)
} else if result.isCancelled {
print("houston, we have a situation: the player cancelled the auth request")
} else {
let credential = FacebookAuthProvider.credential(withAccessToken: FBSDKAccessToken.current().tokenString)
Auth.auth().signInAndRetrieveData(with: credential) { (user, error) in
self.uid = Auth.auth().currentUser?.uid
print("you're in, remember: with great power comes great responsibility!")
self.firstFetch()
}
}
}

关于swift - 取消 Facebook 身份验证时,(快速)项目崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50612511/

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