Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is an iOS app active when the device is locked?

Tags:

ios

iphone

ipad

If a user launches an iOS app, and then locks the device, will the iOS app be active when the device is locked? I do not find the answer in Apple's developer documents.

like image 291
zhoudu Avatar asked Mar 13 '15 10:03

zhoudu


1 Answers

You can find the difference between all the different states by reading the Apple Documentation for UIApplicationDelegete. Look for the section marked Managing State Transition there you will find a table detailing the different states an app can be in.

Not Running

The app has not been launched or was terminated, either by the user or the system.

Inactive

The app is running in the foreground but is not receiving events. (It may be executing other code though.) An app usually stays in this state only briefly as it transitions to a different state. Upon entering this state, the app should put itself into a quiescent state with the expectation of moving to the background or active state shortly.

Active

The app is running in the foreground and receiving events. This is the normal mode for foreground apps. An app in the active state has no special restrictions placed on it. It is the foreground app and should be responsive to the user.

Background

The app is executing code but is not visible onscreen. When the user quits an app, the system moves the app to the background state briefly before suspending it. At other times, the system may launch the app into the background (or wake up a suspended app) and give it time to handle specific tasks. For example, the system may wake up an app so that it can process background downloads, certain types of location events, remote notifications, and other types of events. An app in the background state should do as little work as possible. Apps that request time to process specific types of events should process those events and return control back to the system as quickly as possible.

Suspended

The app is in memory but is not executing code. The system suspends apps that are in the background and do not have any pending tasks to complete. The system may purge suspended apps at any time without waking them up to make room for other apps.

Depending on what entitlements your app has and whether it should run in the background or not your app could be in one of two three states when the phone is on the lock screen. These are Not Running, Background or Suspended

If your app is NOT meant to run in the background it will go into the Not Running state as it will be terminated and will call the method applicationWillTerminate: and when you come back from the lock screen it will relaunch your app as normal.

If your app is entitled to run in the background when you go to the lock screen it will enter a Background state calling applicationDidEnterBackground: and when you come back from the lock screen your app will call the method applicationWillEnterForeground: and will run any code that you require for getting your application in a proper state again. You can create backgroud tasks that will run when the app enters a background state by looking at the UIApplication Documentation for Managing Background Execution

An app will enter a Suspended state when it has background entitlements but isn't running any code and the app is just sat in memory. If the app is in this state the system may purge the app at any time to make room in memory. This doesn't call any methods when entering or exiting this state.

Here is Figure 1 from the Apple documentation

enter image description here

like image 196
Popeye Avatar answered Oct 05 '22 04:10

Popeye