/BackgroundTaskExample

Project example to showcase how to run tasks in the background

Primary LanguageSwift

BackgroundTaskExample

Sumulating background task

Testing background tasks in the debugger build is not really possible but we can simulate it.

  1. Run the app on your device or simulator.
  2. Move the app to the background
  3. Pause the app (|| symbol at the bottom)
  4. Run on the debugger console: e -l objc -- (void)[[BGTaskScheduler sharedScheduler] _simulateLaunchForTaskWithIdentifier:@"com.sergiomartinrubio.BackgroundTaskExample.refresh"]
  5. You should see a log like Handling background task.
  6. For expiring task: e -l objc -- (void)[[BGTaskScheduler sharedScheduler] _simulateExpirationForTaskWithIdentifier:@"com.sergiomartinrubio.BackgroundTaskExample.refresh"]
  7. Handling background task should stop after expiring the task

You may want to test this with a production build in TestFlight.

Resources