PhoneAuth Firebase: Update Phone number

和自甴很熟 提交于 2019-12-04 11:38:04

The answer give above by @bojeil is inaccurate and does not answer the question above. The correct answer would be:

Take a user through the standard IOS-Firebase phone verification process, then after a user is done you will hold a credential variable.

Use this variable to update a users phone number.

(NB: I am not an IOS developer, Google the correct method which to pass the credential variable. In Android that would have been user.updatePhoneNumber(phoneCredential))

I have found an answer where you log in with your email account and update the mobile number into the same account. You may use the solution to log in with phone and update the phone number into the same account and see if it works. Anyway I will be working on this exact solution down in my project and update the answer then. But until then you can try to see if this works. Follow the regular firebase phone auth procedure as given here : 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)

Then do not use the following code

// Sign In The User
Auth.auth().signInAndRetrieveData(with: credential) { _, error in

}

But use this code

Auth.auth().currentUser?.linkAndRetrieveData(with: credential, completion: { _, error in

    if error == nil {
        print("Whopdee doo")

    } else {
        print("Aargh!!!")
    }
})
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!