I wanted to add a background task for iOS13, to replace a setMinimumBackgroundFetchInterval for earlier iOS versions since Fire kindly pointed out it was obsolete
So, I added the BackgroundTasks reference and started with the BGTaskScheduler.shared.register as per BGTaskScheduler | Apple Developer Documentation but Fire says there is no such static member (.shared) and certainly there’s no code completion so am I missing something or is it an issue?
Secondly, I need to support from iOS9 onwards, so have my deployment target set to this, but obviously it doesn’t know about background tasks, and whilst I know I can use
if available(“iOS 13.0”)
for the code, if I try and run it on a simulator earlier than iOS13, then it hangs on startup with
dyld: Library not loaded: /System/Library/Frameworks/BackgroundTasks.framework/BackgroundTasks
It looks like that page is showing Swift code snippets even when ObjC is selected as language, so you see the “swiftified” (I call em “messed up beyond recognition”) names of things. :(.
if you scroll down further, it shows the actual ObjC names, what you want is probably
Hmm, curious. that framework should be weekly linked. @ck, do you remember ow that worked? iirc that should be automatic, no? (update: yeah our docs agree that this should happen automatically: Deployment Targets)
Assuming e is an LLDB debugger command, you can run that on the Fore debug console as well, if you prefix it with lldb, eg:
lldb e -l objc -- (void)[[BGTaskScheduler sharedScheduler] _simulateLaunchForTaskWithIdentifier:@"TASK_IDENTIFIER"]
Ah, I see (and I notice a lot Apple seem to ignore ObjC a lot in their docs). That is right, and I see the issue with CC.
If I type
if available("iOS 13.0") then begin
BGTaskScheduler.
Nothing comes up, but if I remove the first line then CC does indeed work, and sure enough there is the sharedScheduler.registerForTaskWithIdentifier that I was looking for.
It definitely doesn’t run on simulator with 12.2 unless I remove the reference.
Wow, I didn’t realise I could interact with the debug console like that. All this time !
Here you go. Just try it on a 12.2 simulator, and it doesn’t run. Note I didn’t add any code (apart from the info.plist stuff that’s needed), all I did was add the backgroundtasks reference.Archive.zip (118.2 KB)