同时使用 firebase。我的注册运作良好,它注册了用户。但是我的登录在开始时工作正常,但现在它允许任何人转到下一个 View (登录)。
这是我的代码:
登录VC..
import UIKit
import Firebase
class SignInVC: UIViewController {
@IBOutlet weak var emailTF: UITextField!
@IBOutlet weak var passwordTF: UITextField!
@IBAction func onSignInTapped(_ sender: Any) {
guard let email = emailTF.text,
email != "",
let password = passwordTF.text,
password != ""
else {
AlertController.showAlert(self, title: "Missing Information", message: "Please fill in username and password")
return
}
Auth.auth().signIn(withEmail: email, password: password) { (user, error) in
guard error == nil
else {
AlertController.showAlert(self, title: "Oops!", message: error!.localizedDescription)
return
}
guard let user = user else {return}
print(user.email ?? "Missing email address")
print(user.displayName ?? "Missing name")
print(user.uid)
self.performSegue(withIdentifier: "signInSegue", sender: nil)
}
}
//remove keyboard
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
self.view.endEditing(true)
}
}
AlerControllerVC
import UIKit
import Firebase
class AlertController {
static func showAlert(_ inViewController: UIViewController, title: String, message: String) {
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
let action = UIAlertAction(title: "OK", style: .default, handler: nil)
alert.addAction(action)
inViewController.present(alert, animated: true, completion: nil)
}
}
我试了很多次,然后又重写了一遍,但还是不能正常工作,执行时它说:
".SignInVC: 0x7fd99c208280> whose view is not in the window hierarchy!"
最佳答案
请检查您的转场是从按钮到 ViewController 还是从 ViewController 到 ViewController。如果它是从按钮到 VC 那么它不依赖于你写的代码
关于ios - Swift - 在 VC 中登录,允许任何人输入而不验证用户名和密码匹配或保存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47357218/