完成したコード
class LoginView:UIViewController {
@IBOutlet weak var emailField: UITextField!
@IBOutlet weak var passwordField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if AuthHelper().uid() != "" {
dismiss(animated: false, completion: nil)
}
}
@IBAction func onLogin(_ sender: Any) {
AuthHelper().login(email: emailField.text!, password: passwordField.text!, result: {
success in
if success {
self.dismiss(animated: true, completion: nil)
} else {
self.showError()
}
})
}
func showError(){
let dialog = UIAlertController(title: "エラー", message: "メールアドレス、またはパスワードが間違っています。", preferredStyle: .alert)
dialog.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
present(dialog, animated: true, completion: nil)
}
}
コメント