2017-07-09 11 views
0

こんにちは、私は迅速に電話番号の認証のためのチュートリアルに従ってきた、これは私のコードです:Firebase電話番号真偽IOSエラー:オプション(「トークンの不一致」)

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. 
} 

} 

と検証のため、このコード:

Optional("Token mismatch")

ター:

 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. 
} 

} 

私が番号を入力するが、私は、このエラーのエラーを取得する私のアプリを実行しますあなたに助けを求めます

+0

私は同じエラーを表示しています、あなたはその問題の解決策を得ることができますか? –

答えて

0

データベースへの参照があることを確認してください。エラーは、サービスアカウントが電話番号を認識していないことを示しています。ユーザーに電話番号を登録するときは、データベースを更新する必要があります。

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

データベースのURLはデータベースコンソールにあります。

2

プッシュ通知をサーバ側で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) 

} 

、ビルドを共有しながら使用している証明書の種類については、念頭に置いていてください。

SANDBOX_ENDPOINT_URL = 'ssl://gateway.sandbox.push.apple.com:2195'; const SERVICE_ENDPOINT_URL = 'ssl://gateway.push.apple.com:2195';

私はトークンの種類がAPNSのURLを選択するために使用されると考えます。

関連する問題