Bug: Background Modes Tutorial: Getting Started

This is a nice review by Chuck Krutsinger.

I am trying to implement the background fetch functionality but it does not work. Following the code example, I set the app capabilities, then add to my AppDelegate:

  1. register the task ID in didFinishLaunching
  2. add the refresh stub, and the scheduleAppRefresh to the AppDelegate

the BGTaskScheduler.shared.register(forTaskWithIdentifier:
runs, but the handler never does. Neither do either of the refresh methods.

The Tutorial has one add

@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

to AppMain.swift BUT, the tutorial is for Swift 5.5, not SwiftUI, and this should not be needed since obviously I have direct access to the AppDelegate in straight Swift.

Is there anything to try to help get this sample code running?

Hi @ira,

I tried to simulate the background fetch with the final project and had the same issue as described by you.

However, this seems to be the case with the simulator only. If I run it on a physical device and follow the steps that are described in the section Testing Background Fetch of the tutorial, it does call the callback and refresh method as expected.

1 Like

This topic was automatically closed after 166 days. New replies are no longer allowed.