所以这是交易。现在我有一个用户可以注册的viewcontroller,它正在工作(在Firebase控制台中检查)。下一步是我有另一个带有两个字段和一个登录按钮的视图。该登录按钮现在具有到第三个视图的segue,home。但即使在两个文本字段中没有输入任何内容,也可以单击它。该按钮仅在用户输入他在注册视图中创建的详细信息时才起作用,从而登录。
我该怎么做? 已经有登录代码:
@IBAction func loginAction(sender: AnyObject)
{
if self.emailField.text == "" || self.passwordField.text == ""
{
let alertController = UIAlertController(title: "Oops!", message: "Please enter an email and password.", preferredStyle: .Alert)
let defaultAction = UIAlertAction(title: "OK", style: .Cancel, handler: nil)
alertController.addAction(defaultAction)
self.presentViewController(alertController, animated: true, completion: nil)
}
else
{
FIRAuth.auth()?.signInWithEmail(self.emailField.text!, password: self.passwordField.text!) { (user, error) in
if error == nil
{
self.emailField.text = ""
self.passwordField.text = ""
}
else
{
let alertController = UIAlertController(title: "Oops!", message: error?.localizedDescription, preferredStyle: .Alert)
let defaultAction = UIAlertAction(title: "OK", style: .Cancel, handler: nil)
alertController.addAction(defaultAction)
self.presentViewController(alertController, animated: true, completion: nil)
}
在第二个if语句中,您会看到它清除字段以显示登录的工作情况。
我需要的是,只有填写了Firebase数据库中的正确详细信息,用户才能登录。
答案 0 :(得分:0)
不是检查是否有任何错误,而是检查数据是否是这样的用户对象。
FIRAuth.auth()?.signInWithEmail(self.emailField.text!, password: self.passwordField.text!) { (user, error) in
if user != nil
{
let VC = storyboard?.instantiateViewControllerWithIdentifier("Identifier") as! AccountViewController //The file that controls the view
self.presentViewController(VC, animated: true, completion: nil)
}
else
{
let alertController = UIAlertController(title: "Oops!", message: error?.localizedDescription, preferredStyle: .Alert)
let defaultAction = UIAlertAction(title: "OK", style: .Cancel, handler: nil)
alertController.addAction(defaultAction)
self.presentViewController(alertController, animated: true, completion: nil)
}
答案 1 :(得分:0)
我设法通过添加自我修复它。面前
storyboard?.instantiate.
因此创造:
self.storyboard?instantiate.