Firebase Phone Auth

I have Firebase phone auth in my app. However, when the user doesn't input a phone number. It doesn't give an error to put a phone number the app just crashes. This is the code that I have:


  @IBAction func sendPhoneAuthCode(_ sender: Any){
        PhoneAuthProvider.provider().verifyPhoneNumber(phoneNumber.text!, uiDelegate: nil) { (verificationID, error) in
            if let error = error {
                print(error as Any)
                return
            }
            // Sign in using the verificationID and the code sent to the user
            // ...
        }
        UserDefaults.standard.set(verificationID, forKey: "authVerificationID")
    }
Answered by Claude31 in 343463022

Take note thet Firebase Auth does not work on simulator.


See


h ttps://github.com/firebase/FirebaseUI-iOS/issues/358


So, test on device.

>I have Firebase phone auth in my app.


Best to ask them for support w/their SDKs/tools.

Likely, phoneNumber.text is nil


Test this


@IBAction func sendPhoneAuthCode(_ sender: Any) {
     let phoneNum = phoneNumber.text ?? ""     // "" will be an invalid phone number
        PhoneAuthProvider.provider().verifyPhoneNumber(phoneNum, uiDelegate: nil) { (verificationID, error) in
            if let error = error {
                print(error as Any)
                return
            }
            // Sign in using the verificationID and the code sent to the user
            // ...
        }
        UserDefaults.standard.set(verificationID, forKey: "authVerificationID")
    }

continue button call IBAction sendPhoneAuthCode ?


Have you set up all thai is needed to enable App Verification, as decribed in doc:

h ttps://firebase.google.com/docs/auth/ios/phone-auth

Yes, I have I coded the exact same way.

Firebase Phone Auth
 
 
Q