自从使用正确的密码更新到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)
}
}
})
}
}
}
答案 0 :(得分:1)
如果您可以创建电子邮件并且登录有问题,那么就像我的情况一样。只需从yourproject.xcodeproject检查您的钥匙串辅助功能 - >能力 - >钥匙串分享 - >如果它关闭了。
答案 1 :(得分:1)
经过一些研究,这显然是Simulator 10.0不允许Firebase将值写入钥匙串的问题。他们正在研究的东西显然不会影响实际设备上的应用程序。
答案 2 :(得分:0)
您必须确保最初创建用户,因为您必须先创建用户,然后使用创建的用户登录。
@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)
}
}
})
}
}
}