IOS – Can closed (not running) apps access background app refresh

iosmultitasking

Can closed apps (i.e. not running, or suspended) access background app refresh or modify their program state to gain access to background app refresh? And conversely, if background app refresh is disabled, can apps only access data in the foreground?

Example 1: Chat apps still get notifications if they are in the "not running" program state. How do they do this?

Example 2: If I'm saving a note (with background app refresh off), and I return to the homescreen before the note is finished saving, will it continue to save?

From the iOS docs, the app life cycle is pictured below.

State changes in an iOS app

iOS Developer Guide: The App Life Cycle

Best Answer

Do not confuse Suspended with Not Running. Suspended means the app is still in memory but otherwise not utilizing any resources. Not Running means the app is not in memory at all due to being involuntarily terminated, either because the system required resources for a foreground app, or because the user force-quit the app.

Background App Refresh (BAR) =/= "Background" as shown in that diagram:

  • BAR allows apps to update content on a very limited basis, on a schedule set and enforced by iOS, generally about once per day.

  • The Background state shown in that diagram is Background Execution, which allows apps to complete certain tasks in the background. BAR being disabled has no effect on apps being able to use Background Execution.

Background Execution is generally only allowed if an app has not been force-quit by the user (the exception being "location apps"). Apps in any state, including Terminated, can use Background Execution if they meet the requirements below. If necessary, they will be relaunched by the system into the background (again, subject to the force-quit limitations above). See my answer on a similar question:

  • Apps that play audible content to the user while in the background, such as a music player app
  • Apps that record audio content while in the background
  • Apps that keep users informed of their location at all times, such as a navigation app
  • Apps that support Voice over Internet Protocol (VoIP)
  • Apps that need to download and process new content regularly
  • Apps that receive regular updates from external accessories

There is one other case, which is downloading in the background. This is a special case, though, because the app itself is still suspended and the download process is handed off to the system, in case the app has to be terminated by the system to reclaim resources.

What's not in the linked answer is notifications. Non-local notifications are generated on a server somewhere and pushed to the device via Apple Push Notifications (APN). The act of receiving a notification does not indicate the app itself did anything.

In your note example, when the note app transitions to the background, it is given a brief amount of time to save state. If it's in the process of doing something like saving a note, and it cannot complete it in the time allowed, it can ask for an extension, essentially, and then notify the system when it's done so the app can be suspended. This type of background work can be used by any app, not just those that fall under the categories listed above.