Post

Replies

Boosts

Views

Activity

Reply to BGTaskScheduler crashes on iOS 18.4
Attached a symbolicated crash report from one of those Xcode sessions to FB16595418. If I'm understanding this right, it looks like BGTaskScheduler registerForTaskWithIdentifier is already being called internally by the modifier. Thread 2 Crashed: 0 libsystem_kernel.dylib 0x1ef16f1dc __pthread_kill + 8 1 libsystem_pthread.dylib 0x2281a3b40 pthread_kill + 268 2 libsystem_c.dylib 0x1a5f9c234 __abort + 132 3 libsystem_c.dylib 0x1a5f9c1b0 abort + 136 4 libc++abi.dylib 0x2280cd5a0 abort_message + 132 5 libc++abi.dylib 0x2280bbf10 demangling_terminate_handler() + 344 6 libobjc.A.dylib 0x19b560e48 _objc_terminate() + 156 7 libc++abi.dylib 0x2280cc8b4 std::__terminate(void (*)()) + 16 8 libc++abi.dylib 0x2280cfe1c __cxxabiv1::failed_throw(__cxxabiv1::__cxa_exception*) + 88 9 libc++abi.dylib 0x2280cfdc4 __cxa_throw + 92 10 libobjc.A.dylib 0x19b55ee74 objc_exception_throw + 448 11 Foundation 0x19d3a6990 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 288 12 BackgroundTasks 0x236e9d6ec -[BGTaskScheduler _unsafe_registerForTaskWithIdentifier:usingQueue:launchHandler:] + 448 13 BackgroundTasks 0x236e9d4ec -[BGTaskScheduler registerForTaskWithIdentifier:usingQueue:launchHandler:] + 128 14 SwiftUI 0x1a2b77b4c -[BGTaskSchedulerProxy registerForTaskWithIdentifier:launchHandler:] + 220 15 SwiftUI 0x1a34a8028 closure #1 in AppRefreshBackgroundTask.register() + 344 16 SwiftUI 0x1a27cbe15 <deduplicated_symbol> + 1 17 SwiftUI 0x1a293c239 <deduplicated_symbol> + 1 18 SwiftUI 0x1a27ac829 <deduplicated_symbol> + 1 19 libswift_Concurrency.dylib 0x1a9adbcc9 completeTaskWithClosure(swift::AsyncContext*, swift::SwiftError*) + 1
6d
Reply to BGTaskScheduler crashes on iOS 18.4
Thanks for the response. I am still a bit confused however. My understanding is that the .backgroundTask modifier is the replacement for BGTaskScheduler.register in SwiftUI. And the code that runs during the background task is part of that modifier. As per the WWDC22 video Efficiency awaits: Background tasks in SwiftUI, it is used to register the handler. Also worth noting that the video uses a short ID similar to what I did. If I take out the modifier, the app crashes with this message: *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'No launch handler registered for task with identifier notifications' Which indicates that the modifier is indeed used for registering the handler. There's no difference to this behaviour whether I use the short ID notifications or the reverse DNS com.ip18.SubManager.notifications. If the modifier is not there then the app crashes. Interestingly when I simply killed and ran my app from Xcode multiple times, I eventually came across the All launch handlers must be registered before application finishes launching crash in one of those launches. Which is probably what the crash reports are about.
6d
Reply to BGTaskScheduler crashes on iOS 18.4
Hi Kevin, There's no usage of BGTaskScheduler.register anywhere in my app. Am I supposed to call this method at some point? I use the background tasks API in two places currently: Calling BGTaskScheduler.shared.submit during .onChange(of: scenePhase) when newPhase == .active, on the view that appears when my app is launched. It schedules the background task whenever my app is brought to the foreground. .backgroundTask(.appRefresh("notifications")) attached to my WindowGroup. I attached the code snippet of this in my initial bug report. I have just managed to reproduce the crash after quitting and relaunching the app about 100 times. The bug report has been updated with the sysdiagnose and a copy of the crash report.
1w