Can't Simulate BgTaskScheduler to run the tasks in LLDB

`   func submitBackgroundTasks() {
   // Declared at the "Permitted background task scheduler identifiers" in info.plist
   let backgroundAppRefreshTaskSchedulerIdentifier = "com.FeedX.backgroundAlerts"
   let timeDelay = 10.0

   do {
    let backgroundAppRefreshTaskRequest = BGAppRefreshTaskRequest(identifier: backgroundAppRefreshTaskSchedulerIdentifier)
    backgroundAppRefreshTaskRequest.earliestBeginDate = Date(timeIntervalSinceNow: timeDelay)
    try BGTaskScheduler.shared.submit(backgroundAppRefreshTaskRequest)
    print("Submitted task request")
   } catch {
    print("Failed to submit BGTask")
   }
  }

I am able to submit the task and hit the breakpoint but in the LLDB i try to simulate the task using the command

e -l objc -- (void)[[BGTaskScheduler sharedScheduler] _simulateExpirationForTaskWithIdentifier:@"com.FeedX.backgroundAlerts"]

But i get the following error :

error: Error [IRForTarget]: Rewriting an Objective-C constant string requires CFStringCreateWithBytes

Any idea on how to solve this or run the task using a different way? Thanks.

This is working for me:

  1. Using Xcode 14.1 on macOS 13.0.1, I created a new tiny test project.

  2. I added some trivial BG task code to it, just to link in the framework:

    print(BGAppRefreshTaskRequest.self)
    
  3. I ran the app on iOS 16.2.

  4. I set a breakpoint immediately after the line above.

  5. I clicked my test button and stopped at that breakpoint.

  6. I entered the command into the debugger:

(lldb) e -l objc -- (void)[[BGTaskScheduler sharedScheduler] _simulateExpirationForTaskWithIdentifier:@"com.FeedX.backgroundAlerts"]
2023-01-09 11:26:26.846723+0000 Test722970[632:24586] Simulating expiration for task with identifier com.FeedX.backgroundAlerts
2023-01-09 11:26:26.847070+0000 Test722970[632:24586] Task with identifier <decode: missing data> is not currently being simulated

Of course this failed, because my app doesn’t have that BG task, but it shows that I got past the problem you’re hitting.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Can't Simulate BgTaskScheduler to run the tasks in LLDB
 
 
Q