Demo of iOS Background Refersh.

This is example of BGAppRefreshTaskRequest in the Background Tasks framework.

This does the following:

  • Registers the background task in the app delegate’s didFinishLaunchingWithOptions.
  • Schedules the BGAppRefreshTaskRequest in the scene delegate’s sceneDidEnterBackground.
  • All the background task related code is placed in BackgroundTaskManager class to avoid cluttering the app delegate and the scene delegate.
  • The app refresh just does a simple request to https://httpbin.org.
  • All relevant events are logged using Logger (which allows you to watch these iOS events happen on your macOS Console). This is for iOS 14 and later. If you need to support iOS 13, then use os_log instead.
  • This posts UserNotification events so you can also see what’s happening from the device, too.

Reference Link: