ios - 当应用程序状态暂停时,是否有任何功能可以查找应用程序何时从多任务栏中被杀死?
问题描述
当用户在应用程序保持在后台大约 3 到 4 小时后向上滑动从应用程序切换器中删除应用程序时,我想清除应用程序数据。
是否有任何功能或委托可以知道应用程序何时被杀死而没有进入前台。
我希望在用户从应用切换器中终止应用时打开登录页面。否则,它应该打开主页。
解决方案
斯威夫特的解决方案:
在您的 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()
}
仅当应用程序“热启动”时才调用此函数,这意味着如果应用程序之前运行并由用户发送到后台。
推荐阅读
- arrays - 如何将字段(具有 KV 对的对象数组)转换为仅具有值的数组数组?
- sql - Oracle SQL - 计算正在运行的最新值和关联值
- r - 对非股票数据使用 Highcharts 股票类型功能 (R)
- mysql - 执行 SQL “试运行”(来自 Go 应用程序)
- python - 使用 python 的 Twitter REST API
- python - 输入验证为字符串和异常
- python - 如何在 matplotlib 等高线图中添加一个点?
- hibernate-envers - 当审计表没有 ID 记录时,休眠环境抛出未找到实体异常
- python - web.py app.request() 的 Flask/Werkzeug 等价性
- visual-studio-code - Visual Studio Code 选项卡宽度