【发布时间】:2020-09-03 18:06:51
【问题描述】:
我的应用只有纯文本密码字段。但是,我需要用户能够在第一次之后打开应用程序,而不必每次都输入密码,只有第一次。 我不想使用钥匙串,因为密码不是由设备所有者而是由其他人输入的。这是我的密码页面代码,如果这很重要:
import UIKit
class LoginVC: UIViewController {
@IBOutlet weak var textpassword: UITextField!
@IBAction func btnActionLogin(_ sender: Any) {
UserDefaults.standard.set(true, forKey: "status")
if textpassword.text == "KEY" {
runbutton()
}
else {
alertController.addAction(okAction)
alertController.addAction(cancelAction)
self.present(alertController, animated: true, completion: nil)
}
}
// Create the alert controller
let alertController = UIAlertController(title: "Password", message: "Please contact Admin for access to the App", preferredStyle: .alert)
// Create the actions
let okAction = UIAlertAction(title: "OK", style: UIAlertAction.Style.default) {
UIAlertAction in
NSLog("OK Pressed")
}
let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertAction.Style.cancel) {
UIAlertAction in
NSLog("Cancel Pressed")
}
func runbutton() {
let tabBarViewController = UIStoryboard(name: Constants.Storyboard.mainStoryBoard, bundle: nil).instantiateViewController(withIdentifier: Constants.Storyboard.tabBarController) as! UITabBarController
view.window?.rootViewController = tabBarViewController
view.window?.makeKeyAndVisible()
}
func touchBegin(_ touches: Set<UITouch>, with event: UIEvent?) {
view.endEditing(true)
}
struct Constants {
struct Storyboard {
static let homeViewController = "loginvc"
static let tabBarController = "TabBarVC"
static let mainStoryBoard = "Main"
}
}
}
【问题讨论】: