I have a BackgroundTask I'm trying to execute and test, however I get the following error after trying
e -l objc -- (void)[[BGTaskScheduler sharedScheduler] _simulateLaunchForTaskWithIdentifier:@"com.dev.myAppRefreshID"]:
I've made sure to have the correct identifier within the command and my info.plist. Here's the code for my refresh action:
Note: The breakpoint was called at .submit(request)
e -l objc -- (void)[[BGTaskScheduler sharedScheduler] _simulateLaunchForTaskWithIdentifier:@"com.dev.myAppRefreshID"]:
Code Block No task request with identifier <decode: missing data> has been scheduled
I've made sure to have the correct identifier within the command and my info.plist. Here's the code for my refresh action:
Code Block Swift @main class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { BGTaskScheduler.shared.register(forTaskWithIdentifier: "com.dev.myAppRefreshID", using: nil) { task in self.handleAppRefresh(task: task as! BGAppRefreshTask) } return true } func applicationDidEnterBackground(_ application: UIApplication) { scheduleAppRefresh() } func scheduleAppRefresh() { let request = BGAppRefreshTaskRequest(identifier: "com.dev.myAppRefreshID") request.earliestBeginDate = Date(timeIntervalSinceNow: 5 * 60) do { try BGTaskScheduler.shared.submit(request) } catch { print("Could not schedule app refresh: \(error)") } } func handleAppRefresh(task: BGAppRefreshTask) { print("Refresh called") scheduleAppRefresh() let operationQueue = OperationQueue() let refreshOperation = BlockOperation { let refreshManager = BackgroundRefresh() refreshManager.updateInfoForServer() print("Refresh executed") } task.expirationHandler = { refreshOperation.cancel() } refreshOperation.completionBlock = { task.setTaskCompleted(success: !refreshOperation.isCancelled) } operationQueue.addOperation(refreshOperation) } }
Note: The breakpoint was called at .submit(request)