Background Tasks and Refresh
Schedule background work with BGTaskScheduler.
Why Background Tasks Exist
iOS aggressively suspends apps to save battery. To do meaningful work while backgrounded — refreshing a feed, processing a download — you schedule it through BGTaskScheduler. The system decides when to run it, balancing your needs against power and usage patterns.
import BackgroundTasks
// You request work; the system schedules it later
// at an opportune moment (charging, on Wi-Fi, etc.)Two Task Types
There are two kinds: BGAppRefreshTask for short, frequent updates (seconds), and BGProcessingTask for longer, heavier work (minutes) like database maintenance, optionally requiring power or network.
import BackgroundTasks
// BGAppRefreshTask -> quick content refresh
// BGProcessingTask -> long maintenance, can require
// external power / networkAll lessons in this course
- Registering for Push Notifications
- Handling Notification Payloads
- Background Tasks and Refresh
- Notification Actions and Categories