Token Mismatch using Phone Number Authentication - iOS

前端 未结 1 751
心在旅途
心在旅途 2020-12-21 07:52

I am trying to login account using phone number authentication using firebase.

Initially, i deployed the app with my device and it works fine. But when i tried to d

相关标签:
1条回答
  • 2020-12-21 07:56

    Follow steps

    1) Import Firebase and FirebaseAuth

    import Firebase import FirebaseAuth

    2) In didFinishLaunchingWithOptions Configure firebase.

    FirebaseApp.configure()
    

    3) Write these two func in AppDelegate.

      func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        let firebaseAuth = Auth.auth()
        firebaseAuth.setAPNSToken(deviceToken, type: AuthAPNSTokenType.prod)
    
    }
    
    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        let firebaseAuth = Auth.auth()
        if (firebaseAuth.canHandleNotification(userInfo)){
            print(userInfo)
            return
        }
    }
    

    4) In your ViewController class, repeat step first and write code for send OTP on Mobile Number, which you want.

    @IBAction func sendCodeAction(_ sender: Any) {
        let ugrMgr = UserManager.userManager
        let phoneNumber = Auth.auth().currentUser?.phoneNumber
        print(phoneNumber!)
        print(ugrMgr.mobile!)
        PhoneAuthProvider.provider().verifyPhoneNumber("+91" + ugrMgr.mobile!, uiDelegate: nil) { (verificationID, error) in
            if let error = error {
                print(error.localizedDescription)
                mainInstance.ShowAlertWithError(error.localizedDescription as NSString, msg: error.localizedDescription as NSString)
                return
            }
        self.verificationID = verificationID
    
        }
    
    }
    
    0 讨论(0)
提交回复
热议问题