Firebase电话号码身份验证IOS错误:可选(“令牌不匹配”)

Firebase电话号码身份验证IOS错误:可选(“令牌不匹配”),ios,swift,firebase,firebase-authentication,Ios,Swift,Firebase,Firebase Authentication,您好,我已经按照swift中的电话号码验证教程进行了操作,这是我的代码: import UIKit import FirebaseAuth class SignInViewController: UIViewController { @IBOutlet weak var number: UITextField! override func viewDidLoad() { super.viewDidLoad() let myColor : UIColor = UIColo

您好,我已经按照swift中的电话号码验证教程进行了操作,这是我的代码:

import UIKit
import FirebaseAuth

class SignInViewController: UIViewController {

@IBOutlet weak var number: UITextField!

override func viewDidLoad() {
    super.viewDidLoad()


    let myColor : UIColor = UIColor.white
    number.layer.borderWidth = 2.0
    number.layer.borderColor = myColor.cgColor
    number.layer.cornerRadius = 15.0
    number.attributedPlaceholder = NSAttributedString(string :"Enter your number", attributes : [NSForegroundColorAttributeName : UIColor.white] )

}

@IBAction func sendCode(_ sender: Any){
    let alert = UIAlertController(title: "Phone Number", message: "Is this your phone number? \n \(number.text!)", preferredStyle: .alert)

    let action = UIAlertAction(title: "Yes", style: .default) {(UIAlertAction) in
        PhoneAuthProvider.provider().verifyPhoneNumber(self.number.text!){ (verificationID, error) in
            if error != nil{
                print("Error: \(String(describing: error?.localizedDescription))")
            }else {

                let defaults = UserDefaults.standard
                defaults.set(verificationID, forKey: "authVID")
                self.performSegue(withIdentifier: "code", sender: Any?.self)

            }

        }

    }

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


}



override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

}
为了验证此代码:

      import UIKit
      import FirebaseAuth

      class VerificationCodeViewController: UIViewController {

@IBOutlet weak var code: UITextField!

override func viewDidLoad() {
    super.viewDidLoad()

    let myColor : UIColor = UIColor.white
    code.layer.borderWidth = 2.0
    code.layer.borderColor = myColor.cgColor
    code.layer.cornerRadius = 15.0
    code.attributedPlaceholder = NSAttributedString(string :"Enter  your verification code", attributes : [NSForegroundColorAttributeName : UIColor.white] )

    // Do any additional setup after loading the view.
}

@IBAction func verifyCode(_ sender: Any) {
    let defaults = UserDefaults.standard
    let credential : PhoneAuthCredential = PhoneAuthProvider.provider().credential(withVerificationID: defaults.string(forKey: "authVID")!, verificationCode: code.text!)

    Auth.auth().signIn(with: credential) { (user,error) in
        if error != nil {
            print("error: \(String(describing: error?.localizedDescription))")
            }else{

            print("Phone number: \(String(describing: user?.phoneNumber))")
            let userInfo = user?.providerData[0]
            print("Provider ID: \(String(describing: userInfo?.providerID))")
            self.performSegue(withIdentifier: "logged", sender: Any?.self)
        }
    }
}



override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

}
我运行我的应用程序我输入了号码,但我得到了以下错误:

可选令牌不匹配


感谢您的帮助

请确保您有对数据库的引用。错误是服务帐户无法识别电话号码。使用电话号码注册用户时,需要更新数据库

let ref = Database.database().reference(fromURL: "https://MyFireBaseProject.com/")

您的数据库URL可以在数据库控制台中找到。

确保您有对数据库的引用。错误是服务帐户无法识别电话号码。使用电话号码注册用户时,需要更新数据库

let ref = Database.database().reference(fromURL: "https://MyFireBaseProject.com/")

您的数据库URL可以在数据库控制台中找到。

请记住,关于共享生成时使用的证书类型

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {


// If you are using the development certificate you have to use this,
    Auth.auth().setAPNSToken(deviceToken, type: AuthAPNSTokenType.prod)

// If you are using distribution certificate you should use this
    Auth.auth().setAPNSToken(deviceToken, type: AuthAPNSTokenType.sandbox)

// If you want Firebase to automatically detect the type use this.
    Auth.auth().setAPNSToken(deviceToken, type: AuthAPNSTokenType.unknown)

}
这很重要,因为在发送推送通知时,服务器端的URL会发生更改

沙盒\端点\ URL= 'ssl://gateway.sandbox.push.apple.com:2195'; 常数 服务端点ssl://gateway.push.apple.com:2195';


我相信令牌类型将用于选择APN的URL。

请记住,关于共享构建时使用的证书类型

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {


// If you are using the development certificate you have to use this,
    Auth.auth().setAPNSToken(deviceToken, type: AuthAPNSTokenType.prod)

// If you are using distribution certificate you should use this
    Auth.auth().setAPNSToken(deviceToken, type: AuthAPNSTokenType.sandbox)

// If you want Firebase to automatically detect the type use this.
    Auth.auth().setAPNSToken(deviceToken, type: AuthAPNSTokenType.unknown)

}
这很重要,因为在发送推送通知时,服务器端的URL会发生更改

沙盒\端点\ URL= 'ssl://gateway.sandbox.push.apple.com:2195'; 常数 服务端点ssl://gateway.push.apple.com:2195';


我相信令牌类型将用于选择APN的URL。

我正在处理相同的错误,您能解决该问题吗?我正在处理相同的错误,您能解决该问题吗?如果您使用的是必须使用的开发证书。sandbox,如果您使用的是必须使用的开发证书,请更正此问题。沙盒,请更正此问题