【问题标题】:Firebase Authorization with Swift 3.0 not workingSwift 3.0 的 Firebase 授权不起作用
【发布时间】:2016-10-12 12:51:31
【问题描述】:

自从更新到 Swift 3.0 后,即使使用正确的密码,我也会收到不正确的消息。有人在 Firebase 上授权用户时遇到过这个问题吗?

@IBAction func LoginToAccount(_ sender: AnyObject) {

    if let email = emailLogin.text, let password = passwordLogin.text {

    FIRAuth.auth()?.signIn(withEmail: email, password: password, completion: {
        (user, error) in


        if error != nil{
            print("Incorrect")
            let alert = UIAlertController(title: "Error", message: "Incorrect Email or Password.", preferredStyle: UIAlertControllerStyle.alert)
            let action = UIAlertAction(title: "Ok", style: .default, handler: nil)
            alert.addAction(action)
            self.present(alert, animated: true, completion: nil)
        }else{
            if error == nil   {
            self.performSegue(withIdentifier: "AdminSegue", sender: self)

               }
            }
        })
     }
   }
}

【问题讨论】:

  • 你说的不工作是什么意思?
  • 如果您向我们展示错误消息是什么,将会很有用。
  • 我的意思是即使使用正确的密码,我也只会收到消息字符串“不正确的电子邮件或密码”。在更新到 Swift 3.0 之前工作正常
  • 好吧,真奇怪。登录在设备上工作正常,只是在模拟器中不起作用。这只是因为更新到 Xcode 8

标签: ios firebase swift3 firebase-authentication


【解决方案1】:

如果您可以创建电子邮件并在登录时遇到问题,那么就像我的情况一样。只需从 yourproject.xcodeproject -> Capabilities -> keychain Sharing -> On 如果它关闭,检查您的钥匙串可访问性。

【讨论】:

    【解决方案2】:

    经过一些研究,这显然是 Simulator 10.0 不允许 Firebase 将值写入钥匙串的问题。他们显然正在研究的东西,但它不会影响实际设备上的应用程序。

    【讨论】:

      【解决方案3】:

      您必须确保最初已创建用户,因为您必须先创建用户,然后使用创建的用户登录。

      @IBAction func LoginToAccount(_ sender: AnyObject) {
      
          if let email = emailLogin.text, let password = passwordLogin.text {
      
             FIRAuth.auth()!.createUser(withEmail: email, password: password) { user, error in
             if error == nil {
             FIRAuth.auth()!.signIn(withEmail: email, password: password, , completion: { (user, error) in
      
      
                if error != nil{
                   print("Incorrect")
                   let alert = UIAlertController(title: "Error", message: "Incorrect Email or Password.", preferredStyle: UIAlertControllerStyle.alert)
                   let action = UIAlertAction(title: "Ok", style: .default, handler: nil)
                   alert.addAction(action)
                   self.present(alert, animated: true, completion: nil)
                 } else {
                   if error == nil   {
                   self.performSegue(withIdentifier: "AdminSegue", sender: self)
                 }
               }
             })
            }
         }    
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-02-13
        • 2012-04-24
        • 2015-08-09
        • 1970-01-01
        • 2017-06-25
        • 2018-06-15
        • 2013-12-11
        • 2014-10-27
        相关资源
        最近更新 更多