I am trying to determine if user selected the "reset" button after the app restarts. With this code, it will go back to the root controller when the app is open or in the background. Once I terminate the app and re-open, the app is still as if the button was never pressed.
@IBAction func resetClicked(_ sender: Any) {
UserDefaults.standard.set("delete was pressed", forKey: "deleteClicked")
print(UserDefaults.standard.string(forKey: "deleteClicked"))
let vc = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(withIdentifier: infoNavController.ID) as! infoNavController
(UIApplication.shared.connectedScenes.first?.delegate as? SceneDelegate)?.changeRootViewController(vc)
}
I try to call this UserDefault in App Delegate:
func applicationDidBecomeActive(_ application: UIApplication) {
let defaults = UserDefaults.standard
if let check = defaults.string(forKey: "deleteClicked") {
let vc = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(withIdentifier: infoNavController.ID) as! inftoNavController
(UIApplication.shared.connectedScenes.first?.delegate as? SceneDelegate)?.changeRootViewController(vc)
print("Delete was pressed, root controller is now infonavController \(check)")
}
print("applicationDidBecomeActive")
}
But no avail here. I also wrote this code in didfinishlaunchingwithoptions
but it also does not read there. Does anyone have any suggestions for this?