简体   繁体   中英

Swift: I am getting error in firebase mobile authentication

error when call

PhoneAuthProvider.provider().verifyPhoneNumber(txtmobile.text!) { (verificationID, error) in
    if error != nil {
          Model.shared.showAlert(msg: (error?.localizedDescription)!, vc: self)
          return
    }
}

error is "Token mismatch"

first configure your project to firebase

in authentication section in signing method phone enable

download info playlist and add in project by drag and drop

install required pod

app delegate in add

     import Firebase
     import FirebaseAuthUI

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
          FirebaseApp.configure()
    }

in view controller you need to verify phone number

          import FirebaseAuth
                import FirebaseAuthUI
                import FirebasePhoneAuthUI

         class viewController: UIviewcontroller,FUIAuthDelegate {
             override func viewDidLoad() {
                    super.viewDidLoad()

                  FUIAuth.defaultAuthUI()?.delegate = self
                  let phoneProvider = FUIPhoneAuth.init(authUI: FUIAuth.defaultAuthUI()!)
                  FUIAuth.defaultAuthUI()?.providers = [phoneProvider]
                  phoneProvider.signIn(withPresenting: self, phoneNumber: nil)
            }
            func authUI(_ authUI: FUIAuth, didSignInWith user: User?, error: Error?) {
            if let user = user {
            print("I'm logged in")
            }
            else {
               print(error?.localizedDescription ?? "Something went wrong")
            }
      } 

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