Design every step so it is safe to kill and resume.
if retries < 5 { backoff(attempt) }
iOS in depth reels
iOS in depth1 / 3
1 / 5
Two kinds of task
BGAppRefreshTask gives you about 30 seconds to fetch small updates. BGProcessingTask gives minutes for heavier work, usually overnight while charging. You request them; iOS decides when, based on battery, network and how the user uses your app.
2 / 5
Rhythm
Register handlers at launch. In each handler, schedule the next task first, then do bounded work. Set an expiration handler that cancels the work, and always call setTaskCompleted. The OS schedules apps that overrun or forget to complete less often.
3 / 5
Usage decides
iOS learns when your user opens the app and tends to refresh shortly before. A rarely used app gets few background runs, which is why background tasks are an optimisation, never the only route to fresh data.
4 / 5
New in iOS 26
BGContinuedProcessingTask lets a task the user started, like an export or a large upload, keep running after they leave the app, with system progress UI and a cancel button.
In practiceDebug from Xcode with _simulateLaunchForTaskWithIdentifier.
Interview answer
Say it in the interview
On iOS, BGAppRefreshTask handles quick catch-up and BGProcessingTask handles heavy work while charging. Each handler reschedules first, does bounded work, handles expiration and always completes. Foreground sync stays the dependable path, because background time follows how often the user opens the app.
1 / 5
Two kinds of task
BGAppRefreshTask gives you about 30 seconds to fetch small updates. BGProcessingTask gives minutes for heavier work, usually overnight while charging. You request them; iOS decides when, based on battery, network and how the user uses your app.
2 / 5
Rhythm
Register handlers at launch. In each handler, schedule the next task first, then do bounded work. Set an expiration handler that cancels the work, and always call setTaskCompleted. The OS schedules apps that overrun or forget to complete less often.
3 / 5
Usage decides
iOS learns when your user opens the app and tends to refresh shortly before. A rarely used app gets few background runs, which is why background tasks are an optimisation, never the only route to fresh data.
4 / 5
New in iOS 26
BGContinuedProcessingTask lets a task the user started, like an export or a large upload, keep running after they leave the app, with system progress UI and a cancel button.
In practiceDebug from Xcode with _simulateLaunchForTaskWithIdentifier.
Interview answer
Say it in the interview
On iOS, BGAppRefreshTask handles quick catch-up and BGProcessingTask handles heavy work while charging. Each handler reschedules first, does bounded work, handles expiration and always completes. Foreground sync stays the dependable path, because background time follows how often the user opens the app.
BGTaskScheduler without surprises
#ios
❚❚
iOS in depth2 / 3
1 / 5
Transfers outside your process
A background URLSession hands uploads and downloads to a system daemon. Transfers continue while your app is suspended, and even after the system terminates it. When they finish, iOS relaunches your app in the background to tell you.
2 / 5
Rules
Uploads must come from a file, not from memory. For multipart uploads, write each part to its own file and create one task per part. Recreate the session with the same identifier at every launch to reconnect to transfers already in flight.
3 / 5
Events
Implement handleEventsForBackgroundURLSession, keep its completion handler, and call it when the session finishes delivering events. Store which task belongs to which file and part in your database, because the callback may arrive in a brand-new process.
4 / 5
Exception
Force-quitting from the app switcher cancels the app’s background transfers. Your saved list of finished parts makes the restart cheap: on the next launch, only missing parts are queued again.
In practiceSet isDiscretionary for prefetch so iOS can wait for Wi-Fi and power.
Interview answer
Say it in the interview
Big files on iOS go through a background URLSession, one upload task per part file, so the system keeps transferring while we are suspended. We map tasks to parts in SQLite and reconnect the session on every launch. After a user force-quit, only missing parts are queued again.
1 / 5
Transfers outside your process
A background URLSession hands uploads and downloads to a system daemon. Transfers continue while your app is suspended, and even after the system terminates it. When they finish, iOS relaunches your app in the background to tell you.
2 / 5
Rules
Uploads must come from a file, not from memory. For multipart uploads, write each part to its own file and create one task per part. Recreate the session with the same identifier at every launch to reconnect to transfers already in flight.
3 / 5
Events
Implement handleEventsForBackgroundURLSession, keep its completion handler, and call it when the session finishes delivering events. Store which task belongs to which file and part in your database, because the callback may arrive in a brand-new process.
4 / 5
Exception
Force-quitting from the app switcher cancels the app’s background transfers. Your saved list of finished parts makes the restart cheap: on the next launch, only missing parts are queued again.
In practiceSet isDiscretionary for prefetch so iOS can wait for Wi-Fi and power.
Interview answer
Say it in the interview
Big files on iOS go through a background URLSession, one upload task per part file, so the system keeps transferring while we are suspended. We map tasks to parts in SQLite and reconnect the session on every launch. After a user force-quit, only missing parts are queued again.
Background URLSession, the big-file workhorse
#ios#uploads
❚❚
iOS in depth3 / 3
1 / 4
Locked phone, locked database
With complete file protection, files cannot be read while the phone is locked, so background sync fails. Use completeUntilFirstUserAuthentication for the sync database and keychain items: protected at rest, readable after the first unlock.
2 / 4
Silent push is a hint
A push with content-available wakes your app for about 30 seconds, but iOS throttles and coalesces these, especially for apps the user rarely opens. Use them to trigger a pull, and keep foreground sync as the dependable path.
3 / 4
Low Power and Low Data
Low Power Mode delays discretionary work, and Low Data Mode marks networks as constrained. Respect both, and let users override them for transfers they started themselves.
Interview answer
Say it in the interview
The sync database uses completeUntilFirstUserAuthentication so background work can open it after the first unlock. Silent pushes only trigger a pull, and we respect Low Power and Low Data Mode except for transfers the user explicitly started.
1 / 4
Locked phone, locked database
With complete file protection, files cannot be read while the phone is locked, so background sync fails. Use completeUntilFirstUserAuthentication for the sync database and keychain items: protected at rest, readable after the first unlock.
2 / 4
Silent push is a hint
A push with content-available wakes your app for about 30 seconds, but iOS throttles and coalesces these, especially for apps the user rarely opens. Use them to trigger a pull, and keep foreground sync as the dependable path.
3 / 4
Low Power and Low Data
Low Power Mode delays discretionary work, and Low Data Mode marks networks as constrained. Respect both, and let users override them for transfers they started themselves.
Interview answer
Say it in the interview
The sync database uses completeUntilFirstUserAuthentication so background work can open it after the first unlock. Silent pushes only trigger a pull, and we respect Low Power and Low Data Mode except for transfers the user explicitly started.