Testing background tasks in the debugger build is not really possible but we can simulate it.
- Run the app on your device or simulator.
- Move the app to the background
- Pause the app (|| symbol at the bottom)
- Run on the debugger console:
e -l objc -- (void)[[BGTaskScheduler sharedScheduler] _simulateLaunchForTaskWithIdentifier:@"com.sergiomartinrubio.BackgroundTaskExample.refresh"]
- You should see a log like
Handling background task
. - For expiring task:
e -l objc -- (void)[[BGTaskScheduler sharedScheduler] _simulateExpirationForTaskWithIdentifier:@"com.sergiomartinrubio.BackgroundTaskExample.refresh"]
Handling background task
should stop after expiring the task
You may want to test this with a production build in TestFlight.