1

So I am trying to create a phone authentication for our iOS app with swift/swfitUI and Firebase. I followed all the steps provided by Firebase:

  1. enabled the Phone Number sign-in for our Firebase Project
  2. enabled push notifications inside our app in XCode
  3. created and APN key for our app, uploaded it to Firebase with team ID and key ID
  4. setup the reCAPTCHA in XCode
  5. installed firebase-ios-sdk

and added this code (a function that holds the phoneAuth.verifyPhoneNumber function):

import Firebase import FirebaseAuth import FirebaseCore func checkPhoneNumber(phoneNumber: String, completion: @escaping VerificationCompletion) { let phoneAuth = PhoneAuthProvider.provider() print(phoneAuth) print(phoneNumber) FirebaseConfiguration.shared.setLoggerLevel(.debug) phoneAuth.verifyPhoneNumber("+1"+phoneNumber, uiDelegate: nil) { verificationID, error in if let verificationID = verificationID { print(verificationID) } if let error = error { print(error.localizedDescription) completion(false, .failure(error)) return } // Store the verification ID for later use UserDefaults.standard.set(verificationID, forKey: "verificationID") completion(true,.success(verificationID ?? "")) } print("Function checkPhoneNumber run.") } 

this is how I call it:

Button(action: { let impactLight = UIImpactFeedbackGenerator(style: .light) impactLight.impactOccurred() checkPhoneNumber(phoneNumber: user.phoneNumber) { success, error in print(success, error) if success { DispatchQueue.main.async { router.push(.page3) } } else { print("error!") } } }, label: { continueButton() .padding() }) 

Each time I press the button I get only this (function .verifyPhoneNumber not getting called): <FIRPhoneAuthProvider: 0x600003db33e0> (453) 454-33 Function checkPhoneNumber run.

Tried changing the number format. Tried taking the .verifyPhoneNumber out of checkPhoneNumber function, so it is called directly with the button click. I updated the firebase-ios-sdk. I deleted the previous APN key and created a new one. I tried running the app on my iPhone in hopes of a different result. Tried deleting google-info.plst, downloading it again and putting inside XCode. Tried enabling background modes on the simulator. All without success. The problem is that I cannot get any errors, because the function is not working at all.

Tried this enabling this also: Auth.auth().settings.isAppVerificationDisabledForTesting = TRUE

5
  • phoneAuth is getting released as soon as checkPhoneNumber finishes execution. You need to store it somewhere, e.g. in your view model, or use async call variant, that should prevent checkPhoneNumber from finishing until you get the result Commented Jun 8, 2023 at 11:10
  • @PhilDukhov Thanks for the comment. I tried implementing your suggestion by creating a class which has inside private var phoneAuth: PhoneAuthProvider? and the function checkPhoneNumber and then calling the class with the function. It didn't work. I also tried using DispatchQueue.global().async, it didn't work. Maybe I implemented in a wrong way... Any implementaion suggestions or any other solution suggestions that might solve the problem? Commented Jun 10, 2023 at 21:35
  • it's hard to give you any other suggestions without minimal reproducible example Commented Jun 11, 2023 at 6:06
  • @MihajloKovacevic Were you ever able to resolve this? Commented Feb 27, 2024 at 21:53
  • 1
    @Anwar no, I wasn't, we sticked to email 4 digit code Commented Mar 1, 2024 at 0:46

1 Answer 1

0

I had the same issue, but after implementing the methods in the app delegate and scene delegate in this post, I was able to successfully get a sms auth code in a text message

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.