userdefaults不会删除内存中的数据,尽管我已经将其删除。Keychain会执行删除操作。下面是我分享的代码。它会在退出时调用handlelogout函数进行记录,但当我退出时,它没有删除我保存的数据。
@objc func deleteee(){
do {
try keychain.remove("chipnumbernew")
} catch let error {
print("error: \(error)")
}
}
@objc func deleteeetimer(){
UserDefaults.standard.removeObject(forKey: "timertext")
UserDefaults.standard.removeObject(forKey: "timertext2")
UserDefaults.standard.synchronize()
}
@objc func handleLogout(){
do {
deleteee()
deleteeetimer()
try Auth.auth().signOut()
let mainTableVC = LoginViewController()
let navController = UINavigationController(rootViewController: mainTableVC)
self.present(navController, animated: true, completion: {
//
})
} catch let signOutError as NSError {
print ("Giriş Yapılamadı: %@", signOutError)
}
}
override func viewDidLoad() {
super.viewDidLoad()
let token = try? keychain.getString("chipnumbernew")
chip1InfoString = token
if let strtimer = UserDefaults.standard.string(forKey: "timertext") {
print("strtimer", strtimer)
timertextNew.text = strtimer
}
if let strtimer2 = UserDefaults.standard.string(forKey: "timertext2") {
print("strtimer2", strtimer2)
timertext2New.text = strtimer2
} }