PhoneAuth Firebase:更新电话号码

时间:2017-12-04 12:49:43

标签: ios objective-c iphone firebase firebase-authentication

我已经实施了firebase phone auth来验证我项目中的电话号码,并且对我来说工作正常,但无法更新电话号码。就像用户使用电话号码A登录一样,现在他想将其更新为电话号码B.如何解决?

2 个答案:

答案 0 :(得分:0)

@bojeil给出的答案是不准确的,并且不回答上述问题。正确答案是:

让用户浏览standard IOS-Firebase phone verification process,然后在用户完成后,您将持有凭据变量。

使用此变量更新用户电话号码。

(注意:我不是IOS开发人员,Google是传递凭据变量的正确方法。在Android中本来就是user.updatePhoneNumber(phoneCredential)

答案 1 :(得分:0)

我找到了一个答案,您可以在此使用您的电子邮件帐户登录并将手机号码更新为同一帐户。您可以使用该解决方案登录电话,然后将电话号码更新到同一帐户中,然后查看其是否有效。无论如何,我将在我的项目中研究这个确切的解决方案,然后更新答案。但是在那之前,您可以尝试看看是否可行。请遵循此处给出的常规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!!!")
    }
})