当用户在应用程序在后台保留约 3 到 4 小时后通过向上滑动从应用程序切换器中删除应用程序时,我想清除应用程序数据。
是否有任何函数或委托(delegate)可以知道应用程序何时在不进入前台的情况下被杀死。
我希望在用户从应用程序切换器中终止应用程序时打开登录页面。否则,它应该打开主页。
最佳答案
Swift 的解决方案:
在您的 AppDelegate.swift 文件中添加以下函数(如果不存在):
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// clean your apps data here
cleanAppData()
//show the login
showLogin()
}
此函数仅在应用“冷启动”时调用。
这意味着:
- 如果应用程序是第一次启动,它会被调用
- 如果应用程序被 iOS“杀死”
- 如果应用被用户“杀死”
- 如果应用程序在后台运行并再次打开,则不会调用
然后将以下函数(如果不存在)添加到 AppDelegate.swift:
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
// show the homepage
showHomePage()
}
只有当应用程序“热启动”时才会调用此函数,这意味着如果应用程序之前运行并被用户发送到后台。
关于ios - 当应用程序状态暂停时,是否有任何功能可以从多任务栏中查找应用程序何时被杀死?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56254814/