Firebase电话认证Swift

时间:2019-03-31 12:36:33

标签: swift firebase firebase-authentication

我想添加在注册时使用电话号码注册的功能。我写了一个函数,但是不起作用。您可以检查代码吗?我该怎么办?

 func sendCode(_ sender: Any) {
        let alert = UIAlertController(title: "Phone number", message: "Is this your phone number? \n \(emailField.text!)", preferredStyle: .alert)
        let action = UIAlertAction(title: "Yes", style: .default) { (UIAlertAction) in
            PhoneAuthProvider.provider().verifyPhoneNumber(self.emailField.text!, uiDelegate: nil) { (verificationID, error) in

                if error != nil {
                    print("eror: \(String(describing: error?.localizedDescription))")
                } else {
                    let defaults = UserDefaults.standard
                    defaults.set(verificationID, forKey: "authVID")
                    let navController = UINavigationController(rootViewController: CodeEntryView())


                    self.present(navController, animated: true, completion: {

                    })

                }
            }
        }
        let cancel = UIAlertAction(title: "No", style: .cancel, handler: nil)
        alert.addAction(action)
        alert.addAction(cancel)
        self.present(alert, animated: true, completion: nil)
    }

0 个答案:

没有答案