Background work with BGTaskScheduler

Platform & distribution Mid-level Swift 5.0+ iOS 17+ Reviewed By Alok Singh

Pick the fix

A refresh task runs once and never again. Most likely fix?

Options
Hint 1 of 1

How many times does one request run?

Choose an answer, then open Show answer below to check it.

Show answer

Answer: A Submit a new BGAppRefreshTaskRequest inside the handler, and call setTaskCompleted when done

Correct. Each request runs once, so you schedule the next one.

Why not the others?
  • B Set earliestBeginDate to now. It's a minimum time, not a guarantee, and doesn't create a new request.
  • C Register the identifier again in viewDidLoad. Registration happens once at launch.
  • D Use a repeating Timer. Timers don't run while the app is suspended.

30-second answer

Register task identifiers (listed in Info.plist under BGTaskSchedulerPermittedIdentifiers) at launch, then submit requests: BGAppRefreshTaskRequest for short refreshes, BGProcessingTaskRequest for longer maintenance that can require power or network. The system decides when to run them. In the handler, set an expiration handler, call setTaskCompleted, and schedule the next request.

Practise saying it · 45 s. No recording, just a timer

Explain BGTaskScheduler.

Say your answer out loud, then check which of these points you covered:

  • Register and submit
  • Refresh vs processing
  • Complete and reschedule
  • System decides

Deep dive

earliestBeginDate is a minimum, not a schedule.

Test with the debugger command e -l objc -- (void)[[BGTaskScheduler sharedScheduler] _simulateLaunchForTaskWithIdentifier:@"id"].

iOS 26 adds BGContinuedProcessingTask: work the user starts with a tap can keep running in the background, with progress shown in a system Live Activity where they can cancel it.

Users who force-quit an app or disable Background App Refresh prevent refresh tasks.

Common mistakes

  • Forgetting to schedule the next request.
  • Expecting tasks at exact times.

Senior take & follow-ups

Seniors explain that the system decides, and design work to be resumable.

Follow-up questions

Think of your answer first, then open the hint.

  1. Why didn't my task run?

    Show hint

    The system budget, Low Power Mode, force-quit, or a missing identifier.

  2. Refresh or processing?

    Show hint

    Refresh for seconds of work, processing for minutes.

Suggest a fix if something here is wrong or out of date.