Can't change background task identifier

Is there a good explanation somewhere of where background task identifiers are registered and how to modify these? I have entered the "Permitted background task scheduler identifiers" into my xcode target, and it is replicated automatically in Info.plist. I can run the app (which registers the identifier), move it to background (which schedules the task), and then use the debugger to test the launch ("e -l objc -- (void)[[BGTaskScheduler sharedScheduler]...").

However, if I then go back and change the identifier string in the target, plist, and app code, the debugger no longer launches the app in background. It doesn't issue any errors, but just doesn't run it. The change I made to the name is to add an "x" at the end of the string. If I change it back in the target, plist, and app, it works again just fine.

My understanding is that you’re doing this:

  1. Run app with identifier A.

  2. Test it from LLDB. It works.

  3. Change the app to use identifier B.

  4. Test it from LLDB. It fails.

If you delete the app from the device between steps 3 and 4, does that help?

Share and Enjoy

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

What you described is correct. I have tried deleting app between 3 and 4, and it still fails. The identifier I'm using (not that this should matter) is: "com.dlsa.BackgroundProcesses.refresh" and I when I change it to: "com.dlsa.BackgroundProcesses.refreshx" it fails.

The command I'm using is: e -l objc -- (void)[[BGTaskScheduler sharedScheduler] _simulateLaunchForTaskWithIdentifier:@"com.example.apple-samplecode.ColorFeed.refreshx"]

I know it is registering the task correctly, because if I run the app and enter the old command (without the "x") I get:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'No launch handler registered for task with identifier {public}@' *** First throw call stack: (0x1a55be69c 0x19d873c80 0x1a4b1cdd8 0x21bb89b0c 0x21bb882bc 0x1a5503794 0x1a550322c 0x1a44d6440 0x1a44d5fc0 0x1a44d5928 0x20f517b44 0x20f50a4b8 0x105852bb4 0x105871ca8 0x10585a7c4 0x10585b728 0x1058685f8 0x105867c2c 0x20f4b7964 0x20f4b7a04) libc++abi: terminating due to uncaught exception of type NSException

but if I re-run with the correct command, I don't get the exception, but it doesn't run the background task.

Switching back to name without "x" all works fine.

I have tried deleting app between 3 and 4, and it still fails

Hmmm, I was hoping that’d help. When you build and run from Xcode, it does an incremental update and it’s easy to imagine the Background Tasks subsystem not handling that correctly.

Let’s try something else: In between steps 3 and 4, delete the app and restart your device. Does it still fail?

Not that I’m proposing this as an actual workaround, I’m just trying to get a handle on the scope of the problem.

Share and Enjoy

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

Here's what I did:

  1. Ran with original name. Debug commands work fine.
  2. Stopped app in xcode, and changed names (added "x" at end of identifier in target (replicated to Info.plist), and code
  3. Removed app from phone
  4. Shutdown phone and rebooted.
  5. Ran with new names from xcode...same problem
  6. Switched name back...runs fine.

I have also created a "slimmed-down" version of my app, using a new name: com.dlsa.BackgroundProcesses.refresh

Once again, after running the first time, it will not let me change the name.

5. Ran with new names from xcode...same problem

Well, that’s just annoying.

At this point my only advice is that you file a bug about this. Please post your bug number, just for the record.

Share and Enjoy

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

Thanks! I'll file bug report.

I still have two TSI's available on my Developer Program. Would it be worthwhile to ask for help on this through the TSI? My concern is that when I first found this problem, it was when I was testing an app I'm working on. I think I changed the identifier a few times, and I don't know if I can retrace back to the original one (there seem to be some git bugs in xcode, so sometimes getting back to old version is difficult), so I may never be able to get the app to work without either: 1) figuring out what name is "registered" that will work, or 2) finding a way to "de-register" so I can put in a name that will work until the bug is fixed (if it is fixed).

I guess my question is: how deep will Apple tech support go to help me get my app working, given that there is a bug I may not be able to workaround? (Does that make sense?)

Any insights will be appreciated.

I filed bug report: FB13532365

FB13532365

Thanks!

Would it be worthwhile to ask for help on this through the TSI?

It’s hard to say in advance. Such is the nature of TSIs in general. We can dig into an issue but there’s no guarantee that a workaround will pop out.

Share and Enjoy

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

So if I file a TSI, and it turns out to be an un-workaroundable (not sure that's a word) bug, does it still count as against my quota?

Aha! I figured it out! I guess it would help to read the docs a little more carefully!

It seems that only 1 refresh task can be scheduled at a time. If I do a BGTaskScheduler.shared.cancelAllTaskRequests() when I start up the app, to insure there aren't any "lingering" refresh tasks, I can use whatever names I want, and change them at will.

Sorry to take up your time, but I learned to read better, and to file a bug (which I will close), so not a total loss (at least for me).

I'll be more careful next time!

Thanks again...David

does it still count as against my quota?

Yes. TSI are consumed when a DTS engineer spends a significant amount of time working on your issue.

I figured it out!

Cool. Thanks for closing the loop here.

Share and Enjoy

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

Can't change background task identifier
 
 
Q