我想使用设置包从应用程序中注销。
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
//enable_logout key for logout switch identifire in setting budle plist.
let userLogout = UserDefaults.standard.bool(forKey: "enabled_logout")
print(userLogout)
let userLogin = UserDefaults.standard.bool(forKey: "isUserLogin")
if userLogin {
let homeController = HomeController()
let homeNav = UINavigationController.init(rootViewController: homeController)
let aboutController = AboutController()
let aboutNav = UINavigationController.init(rootViewController: aboutController)
let userBaseController = UserBaseInfoController()
let userBaseNav = UINavigationController.init(rootViewController: userBaseController)
tabbarController.viewControllers =[homeNav,userBaseNav,aboutNav]
self.window?.rootViewController = tabbarController
}
else {
let login = LoginController()
self.window?.rootViewController = login
}
return true
}
我在 appDelegate 中添加了此代码,我想当用户在设置中启用注销开关然后返回应用程序显示登录 View 时,但是当启用开关并返回应用程序时 appDelegate 不调用并且我的 key 不改变。
我正在解决这个问题,而是检查 didFinishLaunchingWithOptions
方法中的 enable_logout
键,我检查了 applicationWillEnterForeground
方法。
这是我的代码:
func applicationWillEnterForeground(_ application: UIApplication) {
let userLogout = UserDefaults.standard.bool(forKey: "enable_logout")
print(userLogout)
if !userLogout {
let homeController = HomeController()
let homeNav = UINavigationController.init(rootViewController: homeController)
let aboutController = AboutController()
let aboutNav = UINavigationController.init(rootViewController: aboutController)
let userBaseController = UserBaseInfoController()
let userBaseNav = UINavigationController.init(rootViewController: userBaseController)
tabbarController.viewControllers = [homeNav,userBaseNav,aboutNav]
self.window?.rootViewController = tabbarController
}
else {
let login = LoginController()
self.window?.rootViewController = login
}
}
关于ios - 从应用程序设置中的应用程序注销,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40956241/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (https://ogeek.cn/) | Powered by Discuz! X3.4 |