0Pricing
Swift Academy · Lesson

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 / network

All lessons in this course

  1. Registering for Push Notifications
  2. Handling Notification Payloads
  3. Background Tasks and Refresh
  4. Notification Actions and Categories
← Back to Swift Academy