让用户使用手机验证登录

时间:2017-08-14 11:01:27

标签: swift firebase firebase-authentication

我无法弄清楚如何在firebase中查看电话号码,我不知道如何让用户保持登录状态。

我尝试了很多代码并没有为我效劳:

class VerifyCodeVC: UIViewController {

    @IBOutlet weak var Code: UITextField!

    override func viewDidLoad() {
        super.viewDidLoad()
    }

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

    @IBAction func Verify(_ 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: "maininf", sender: Any?.self)

            }
        }
    }
}

0 个答案:

没有答案