Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know whether app is terminated by user or iOS (after 10min background)

How to know whether app is terminated by user or by iOS when restart app>

'By user' means "by Double-clicking Home Button and pressing - button". killed by user

'By iOS' means "app become background running state, and iOS terminate app after 10 mins"

like image 838
ChangUZ Avatar asked Sep 08 '11 05:09

ChangUZ


People also ask

Will iOS terminate the app running in background after a specific time?

No, there is no specific time defined for this.

How long does iOS app background take?

Typically, iOS policies permit up to 10 minutes of background time after the app is suspended or the device is locked. In practice this time can vary wildly, but we request as much time as the system will allow.

How do I know if apps are running in the background iOS?

Open the Settings app and tap General, and then Background App Refresh. You'll see a list of every app that currently has permission to run in the background.

When app is killed iOS?

It varies per device, and is tighter on older devices. Prior to iPhone 6s, this limit is around 200 MB max, but after 6S, it grows higher. When this limit is exceeded, your app will be killed immediately. “jetsam” is what's known as a “Memory Pressure Exit”, and is the most common type of app termination.


2 Answers

If your app is in suspended state the applicationWillTerminate will never get called regardless who killed the app iOS or user.

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.

Just read this reference

applicationWillTerminate:—Lets you know that your app is being terminated. This method is not called if your app is suspended.

Here is the table of various states enter image description here

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.

like image 167
Inder Kumar Rathore Avatar answered Sep 30 '22 20:09

Inder Kumar Rathore


iOS might terminate your app if system resources are low - if this happens, you will see applicationWillTerminate.

It used to be that if a user killed the app (task manager, via the button double-click and then hits the red '-') it's a SIGKILL and applicationWillTerminate is not called. A report mid-2013 suggests this has changed and applicationWillTerminate now is called.

You could use NSUserDefaults to write some state bit in applicationWillTerminate to note that this function was called and presumably that's a system kill rather than a user kill.

like image 41
Adam Eberbach Avatar answered Sep 30 '22 19:09

Adam Eberbach