Mobile Development 12 min read

iOS App Background Execution Techniques and Implementation Guide

This article explains the various iOS app background execution states, short‑term background tasks, long‑term keep‑alive methods such as silent audio, continuous location, background downloads, and BGTaskScheduler, and provides Objective‑C code examples and configuration steps for developers.

360 Tech Engineering
360 Tech Engineering
360 Tech Engineering
iOS App Background Execution Techniques and Implementation Guide

The author investigates whether an iOS app can stay alive in the background and summarizes the findings. iOS apps have several runtime states (Unattached, Foreground Inactive, Foreground Active, Background, Suspended) that differ before and after iOS 13.0. Short‑term background execution can be achieved with - (void)applicationDidEnterBackground:(UIApplication *)application { ... } using beginBackgroundTaskWithName:expirationHandler: , which on iOS 12 devices lasts about 175 seconds and on iOS 13 devices about 31 seconds.

Long‑term background keep‑alive methods include playing silent audio, enabling continuous location updates, performing background downloads, and using the iOS 13+ BGTaskScheduler framework. For audio‑based keep‑alive, an AVAudioPlayer is configured to loop a silent file indefinitely. For location‑based keep‑alive, the app requests always‑authorization and sets allowsBackgroundLocationUpdates = YES . Background downloads use a background NSURLSessionConfiguration with sessionSendsLaunchEvents = YES and discretionary = YES .

Using BGTaskScheduler , the app registers tasks in - (void)registerBgTask , schedules them with BGAppRefreshTaskRequest , and handles execution in - (void)handleAppRefresh:(BGAppRefreshTask *)appRefreshTask . The handler posts a notification, logs the refresh time to a file, and marks the task as completed.

All code snippets are provided in Objective‑C and wrapped in ... tags. The article also shows how to simulate background task launches via Xcode console commands and how to view log files using the Files app. A demo repository is linked: https://github.com/QiShare/QiAppRunInBackground . Finally, a list of reference URLs for further reading is included.

mobile developmentiOSObjective-CBackground ExecutionBGTaskSchedulerlocation updatessilent audio
360 Tech Engineering
Written by

360 Tech Engineering

Official tech channel of 360, building the most professional technology aggregation platform for the brand.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.