我使用 UserDefaults 来制作登录屏幕。我的问题是我需要一个管理员让苹果的审查员可以直接登录我的应用程序而无需再次注册。接下来我该怎么办?请帮助我!谢谢!
这是我的代码:
//This is register's code
@IBOutlet weak var userRegisterTextField: UITextField!
@IBOutlet weak var userRegisterPasswordTextField: UITextField!
@IBOutlet weak var repeatPasswordTextField: UITextField!
@IBAction func registerButton(_ sender: Any) {
let userRegister = userRegisterTextField.text
let userRegisterPassword = userRegisterPasswordTextField.text
let userRepeatPassword = repeatPasswordTextField.text
// save the data that user register in.
UserDefaults.standard.set(userRegister, forKey: "userRegister")
UserDefaults.standard.set(userRegisterPassword, forKey: "userRegisterPassword")
UserDefaults.standard.synchronize()
}
//This is login's code.
@IBOutlet weak var userName: UITextField!
@IBOutlet weak var userPassword: UITextField!
@IBOutlet weak var loginText: UILabel!
@IBOutlet weak var loginButton: UIButton!
@IBAction func loginButton(_ sender: Any) {
let userLogin = userName.text
let userPasswordText = userPassword.text
let userPasswordStored = UserDefaults.standard.string(forKey: "userRegisterPassword")
let userLoginStored = UserDefaults.standard.string(forKey: "userLoginStored")
let vc = self.storyboard?.instantiateViewController(withIdentifier: "TabBarController") as! UITabBarController
/*userID and password must the same as the data that user registered before*/
if userLoginStored == userLogin {
if userPasswordStored == userPasswordText {
UserDefaults.standard.set(true, forKey: "isUserLoggedIn")
UserDefaults.standard.synchronize()
self.present(vc, animated: true, completion: nil)
}
} else {
loginText.text = "Your userID or password is wrong. Please try again"
}
}