BackgroundFetch Crash in iOS15 and iOS16
Monitor Type: Mach Exception
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: KERN_INVALID_ADDRESS at 0x00000001df8354b0
Crashed Thread: 0
Pthread id: 23896613
Thread 0 Crashed:
0 BaseBoard -[_BSActionResponder action_sendResponse:] + 528
1 BaseBoard -[_BSActionResponder action_sendResponse:] + 520
2 BaseBoard -[BSAction sendResponse:] + 76
3 UIKitServices -[UISFetchContentInBackgroundAction sendResponse:] + 100
4 UIKitCore __91-[UIApplication _handleNonLaunchSpecificActions:forScene:withTransitionContext:completion:]_block_invoke_3 + 60
5 UIKitCore -[_UIAfterCACommitBlock run] + 72
6 UIKitCore -[_UIAfterCACommitQueue flush] + 176
7 UIKitCore _runAfterCACommitDeferredBlocks + 496
8 UIKitCore _cleanUpAfterCAFlushAndRunDeferredBlocks + 108
9 UIKitCore _UIApplicationFlushCATransaction + 72
10 UIKitCore _UIUpdateSequenceRun + 84
11 UIKitCore schedulerStepScheduledMainSection + 172
12 UIKitCore runloopSourceCallback + 92
13 CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28
14 CoreFoundation __CFRunLoopDoSource0 + 176
15 CoreFoundation __CFRunLoopDoSources0 + 244
16 CoreFoundation __CFRunLoopRun + 836
17 CoreFoundation CFRunLoopRunSpecific + 612
18 GraphicsServices GSEventRunModal + 164
19 UIKitCore -[UIApplication _run] + 888
20 UIKitCore UIApplicationMain + 340
21 app main (main.m:43)
22 (null) 0x00000001f694e960 0x0 + 8431921504
iOS15、iOS16 crashed in the background after enable the BackgroundFetch function, According to the log, all crash are in background and the crash is almost located. but how to fix it ??
- (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
if (self.currentCompletionHandler && self.currentCompletionHandler != completionHandler) {
self.currentCompletionHandler(UIBackgroundFetchResultNoData);
}
self.currentCompletionHandler = completionHandler;
//do something
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (self.currentCompletionHandler) {
** self.currentCompletionHandler(UIBackgroundFetchResultNewData); //crash line code
** self.currentCompletionHandler = nil;
}
});
}