Geek Culture

A new tech publication by Start it up (https://medium.com/swlh).

Follow publication

Member-only story

iOS Application States

Varga Zolt
Geek Culture
Published in
3 min readJan 12, 2022

--

Most common use case is when the user taps the app icon and the application starts.
1.) App wakes up
2.) You do some initialisation (Optional, but almost always used)
3.) Create some UI, Screen
4.) Trigger some API calls (Optional, but often used)

Basic lifecycle

While this is happening, app state (UIApplication.State) is changing.

Inactive

The app is running in the foreground but is not receiving events. Transitional state (multitasking UI). The app is either going to or coming from Active state. Like open another app, home button tap, screen turned off by power button, terminate the app by swipe, caller…

Transitions:
1.) Not Running -> Inactive -> Active
2.) Active -> Inactive -> Background
3.) Background -> Inactive -> Active

Active

The app is running in the foreground and currently receiving events. The app is onscreen and running and ready for user interaction.

Background

The app is running in the background.
Can be launched by the system by Push / Local Notification, Time Sensitive Events, Background Processing, Background Fetching
Can perform some logic. In this state after some time the OS kills the app.
On iOS12 it is around 180s (not officially confirmed by Apple).
On other OS versions it is mostly around 10s in my experience.
It can be extended by beginBackgroundTask(expirationHandler:) or beginBackgroundTask(withName:expirationHandler:).
If you want to know exactly the time, UIApplication.shared.backgroundTimeRemaining can show it.
Keep in mind that with the break point it will still be ticking as this is OS specified time. Also if you see some huge number that means it is “infinite” and termination is not triggered.

--

--

Varga Zolt
Varga Zolt

Written by Varga Zolt

 Mobile Tech Lead📱 🧑‍💻 Writing about new Technologies. Coding for fun since 2005, for food since 2008 🚀 Site: https://bit.ly/skyspiritlabs

Write a response