简体   繁体   中英

Firebase Phone Auth

I'm trying to add Firebase Phone Auth to an app that I'm making in XCode. However, I'm having trouble with steps 3 of the firebase documentation and everything after that.

I don't understand where my code is supposed to go. I try some of it already and I attached the image of what I have done so far. Please help.

Thank you.

Ok, the code seems right. Now you must add another textfield where the user can add the verification code arrived from the SMS.

In a new method triggered by the user after adding the code you must set a FIRAuthCredential like in the code of the example:

FIRAuthCredential *credential = [[FIRPhoneAuthProvider provider]
credentialWithVerificationID:verificationID
            verificationCode:newTextField.text!];

And then do the signin with:

[[FIRAuth auth] signInAndRetrieveDataWithCredential:credential
                                     completion:^(FIRAuthDataResult * _Nullable authResult,
                                                  NSError * _Nullable error) {
 if (error) {
   // ...
   return;
 }
 // User successfully signed in. Get user data from the FIRUser object
 if (authResult == nil) { return; }
 FIRUser *user = authResult.user;
 // ...
}];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM