This question already has an answer here:
这个问题已经有了答案:
- How to know whether app is terminated by user or iOS (after 10min background) 2 answers
- 如何知道app是否被用户或iOS (10min后台)终止?
If app completed ~10 min in background, it will be in suspended mode. App can be killed by below two ways:
如果app在后台完成~ 10min,将处于暂停模式。App可以通过以下两种方式被杀死:
-
iOS can kill the app : In this scenario "applicationWillTerminate" will call.
iOS可以杀死应用程序:在这个场景中,“applicationWillTerminate”将调用。
-
User can kill apps explicitly using the multitasking UI.(by Double-clicking Home Button and pressing - (red)button)
用户可以使用多任务UI明确地杀死应用程序。(双击Home键和按下(红色)按钮)
In second scenario how can we get that app killed by user?
在第二种情况下,我们如何让这个应用程序被用户杀死?
I check below question but no fruitful result: App killed by user
我检查下面的问题但没有结果:应用程序被用户杀死
1 个解决方案
#1
14
If your app is in suspended state the applicationWillTerminate
will never get called regardless who killed the app iOS or user.
如果你的应用程序处于暂停状态,无论谁杀了app iOS或用户,它都不会被调用。
Your applicationWillTerminate
will only call when your app is in background and it gets killed (either by iOS or user) the term background means that it is running in background not in suspended state.
你的应用程序将只在你的应用程序处于后台时才会调用它(被iOS或用户杀死)。
Just read this reference
刚读这个引用
applicationWillTerminate:—Lets you know that your app is being terminated. This method is not called if your app is suspended.
applicationWillTerminate: -让你知道你的应用程序正在被终止。如果应用程序挂起,则不调用此方法。
Here is the table of various states
这是各种状态的表格
Background - The app is in the background and executing code. Most apps enter this state briefly on their way to being suspended. However, an app that requests extra execution time may remain in this state for a period of time. In addition, an app being launched directly into the background enters this state instead of the inactive state. For information about how to execute code while in the background, see Background Execution.
后台——应用程序在后台执行代码。大多数应用程序都是暂时进入这个状态,然后被暂停。但是,请求额外执行时间的应用程序可能会在这个状态中停留一段时间。此外,直接启动到后台的应用程序将进入此状态,而不是非活动状态。有关如何在后台执行代码的信息,请参见后台执行。
#1
14
If your app is in suspended state the applicationWillTerminate
will never get called regardless who killed the app iOS or user.
如果你的应用程序处于暂停状态,无论谁杀了app iOS或用户,它都不会被调用。
Your applicationWillTerminate
will only call when your app is in background and it gets killed (either by iOS or user) the term background means that it is running in background not in suspended state.
你的应用程序将只在你的应用程序处于后台时才会调用它(被iOS或用户杀死)。
Just read this reference
刚读这个引用
applicationWillTerminate:—Lets you know that your app is being terminated. This method is not called if your app is suspended.
applicationWillTerminate: -让你知道你的应用程序正在被终止。如果应用程序挂起,则不调用此方法。
Here is the table of various states
这是各种状态的表格
Background - The app is in the background and executing code. Most apps enter this state briefly on their way to being suspended. However, an app that requests extra execution time may remain in this state for a period of time. In addition, an app being launched directly into the background enters this state instead of the inactive state. For information about how to execute code while in the background, see Background Execution.
后台——应用程序在后台执行代码。大多数应用程序都是暂时进入这个状态,然后被暂停。但是,请求额外执行时间的应用程序可能会在这个状态中停留一段时间。此外,直接启动到后台的应用程序将进入此状态,而不是非活动状态。有关如何在后台执行代码的信息,请参见后台执行。