BackgroundTasks Refresh debug error: No task request with identifier <decode: missing data> has been scheduled

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"]:
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)
It seems that after attempting to run the command multiple times, it will tell me it's registered 3/4 of the time and work 1/4 of the time, even though I've used the same breakpoint and command.
After even further inspection, the task has decided it wants to do so 100% of the time. I don't know what could be causing it.
I've been seeing this same issue for the past couple weeks
Set request.earliestBeginDate = Date(timeIntervalSinceNow: 5 * 60) to
request.earliestBeginDate = Date(timeIntervalSinceNow: 0)
and it will work.
Check in the settings of your phone. Is the background app refresh enabled? You might have it turned off.
Enabling Background app refresh setting + Device reboot might help.

I read somewhere on stack overflow that the queue only holds one background task at a time. Is that true? Is that only during development? What happens to the other background tasks that are submitted if the queue only holds one background task? This could be the problem.

I think your app has at first to enter the background, so scheduleAppRefresh is executed. Then there is no error message.

@ccamaisa a question please, where and how do i run the command "e -l objc -- (void)[[BGTaskScheduler sharedScheduler] _simulateLaunchForTaskWithIdentifier:@"com.dev.myAppRefreshID"]" you posted?

BackgroundTasks Refresh debug error: No task request with identifier &lt;decode: missing data&gt; has been scheduled
 
 
Q