【问题标题】:PhoneAuth Firebase: Update Phone number电话验证 Firebase:更新电话号码
【发布时间】:2018-05-17 22:40:08
【问题描述】:
我已经实施了 Firebase 电话身份验证来验证我的项目中的电话号码,并且它对我来说工作正常,但无法更新电话号码。就像用户使用电话号码 A 登录,现在他想将其更新为电话号码 B。如何解决?
【问题讨论】:
标签:
ios
objective-c
iphone
firebase
firebase-authentication
【解决方案1】:
我找到了一个答案,您使用您的电子邮件帐户登录并将手机号码更新到同一帐户。您可以使用该解决方案通过手机登录并将手机号码更新到同一帐户中,看看是否有效。无论如何,我将在我的项目中研究这个确切的解决方案,然后更新答案。但在那之前,您可以尝试看看这是否有效。按照此处给出的常规 Firebase 电话身份验证程序进行操作:https://firebase.google.com/docs/auth/ios/phone-auth
PhoneAuthProvider.provider().verifyPhoneNumber(phoneNumber, uiDelegate: nil) { (verificationID, error) in
if let error = error {
self.showMessagePrompt(error.localizedDescription)
return
}
// Sign in using the verificationID and the code sent to the user
// ...
}
let credential = PhoneAuthProvider.provider().credential(
withVerificationID: verificationID,
verificationCode: verificationCode)
那就不要使用下面的代码
// Sign In The User
Auth.auth().signInAndRetrieveData(with: credential) { _, error in
}
但是使用这段代码
Auth.auth().currentUser?.linkAndRetrieveData(with: credential, completion: { _, error in
if error == nil {
print("Whopdee doo")
} else {
print("Aargh!!!")
}
})