我需要帮助使用我的代码。这里是链接到我的loginviewcontroller的代码,以及我在互联网上无法找到的任何地方解释这一点。我试图让用户第一次登录时,他们会一直登录,直到他们退出为止,这样用户就不必每次打开应用程序时都继续登录。我试过了钥匙圈和所有这些,但我无法弄清楚。我错过了什么?我摆脱了试图保存信息的垃圾代码。自动登录Firebase用户
import UIKit
import Firebase
import FirebaseStorage
import FirebaseDatabase
import FirebaseAuth
class LoginViewController: UIViewController {
@IBOutlet weak var emailField: UITextField!
@IBOutlet weak var pwField: UITextField!
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(true)
if FIRAuth.auth()?.currentUser == nil {
let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Login") as! UsersViewController
present(vc, animated: true, completion: nil)
}
}
@IBAction func loginPressed(_ sender: Any) {
guard emailField.text != "", pwField.text != "" else {return}
FIRAuth.auth()?.signIn(withEmail: emailField.text!, password: pwField.text!, completion: { (user, error) in
if let error = error {
print(error.localizedDescription)
}
if user != nil {
let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "centralvc")
self.present(vc, animated: true, completion: nil)
}
})
}
}