应用程序在后台模式下仅在iOS 13上崩溃
该应用程序仅在iOS 13上崩溃,当我看到详细报告时,报告提到该应用程序崩溃时在后台。没有引用崩溃日志中提到的代码行,我可以在其中找到导致崩溃的代码行。请建议是否有其他人也面临过此类问题 崩溃:com.apple.main-thread EXC错误访问内核无效地址0x0000000f5e5f9c3c应用程序在后台模式下仅在iOS 13上崩溃,ios,objective-c,uibackgroundtask,backgroundtaskidentifier,Ios,Objective C,Uibackgroundtask,Backgroundtaskidentifier,该应用程序仅在iOS 13上崩溃,当我看到详细报告时,报告提到该应用程序崩溃时在后台。没有引用崩溃日志中提到的代码行,我可以在其中找到导致崩溃的代码行。请建议是否有其他人也面临过此类问题 崩溃:com.apple.main-thread EXC错误访问内核无效地址0x0000000f5e5f9c3c 这就是我在beginBackgroundTask(expirationHandler:)中所做的。请纠正我在这里的错误 - (void)applicationDidEnterBackground
这就是我在beginBackgroundTask(expirationHandler:)中所做的。请纠正我在这里的错误
- (void)applicationDidEnterBackground:(UIApplication *)application {
self.isAppLaunched = NO;
_bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
// Clean up any unfinished task business by marking where you
// stopped or ending the task outright.
[self cancelAllProductDownloadsInProgress];
dispatch_async(_MAGICBOX.databaseQueue, ^{
[application endBackgroundTask:self.bgTask];
self.bgTask = UIBackgroundTaskInvalid;
});
}];
//Dismiss keyboard
[self.window endEditing:YES];
}
关键的一行是
workspaceNoteAssertionExpirationCommitten
。您正在请求一个后台任务(可能是使用beginBackgroundTask(expirationHandler:)
),当它过期时,您无法进行正确的清理。因此,你的应用程序将被杀死。查看你是否在代码中可能相关的任何地方调用了stringWithFormat
。但这只出现在iOS 13中,以前的版本中没有报告过一个实例。还有,我该如何进行适当的清理呢?谢谢@matt的回答,但我仍然不明白为什么只有iOS 13版本才会出现这种情况。然而,在低于iOS 13的版本上,这并没有崩溃。现在您已经展示了您的实现,它证实了,正如我告诉您的,您的实现是完全错误的。我应该看到对应用程序endBackgroundTask
的两个调用,一个用于在成功完成任务时调用,另一个用于在时间用完时调用。我在前面的评论中给你的链接将告诉你后台任务的正确结构。使用这种结构,而不是其他。至于为什么这不会给你在iOS 13之前的版本带来麻烦。。。这不是我(或你)真正关心的问题,但一个原因可能是在iOS 13之前,你有更多的时间完成你的后台任务,所以你的时间不会过期。
- (void)applicationDidEnterBackground:(UIApplication *)application {
self.isAppLaunched = NO;
_bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
// Clean up any unfinished task business by marking where you
// stopped or ending the task outright.
[self cancelAllProductDownloadsInProgress];
dispatch_async(_MAGICBOX.databaseQueue, ^{
[application endBackgroundTask:self.bgTask];
self.bgTask = UIBackgroundTaskInvalid;
});
}];
//Dismiss keyboard
[self.window endEditing:YES];
}