【发布时间】:2019-03-29 17:50:18
【问题描述】:
当我在后台模式下获取应用程序时,应用程序崩溃并显示以下日志。
这是崩溃的设备日志:
Exception Type: EXC_CRASH (SIGKILL)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Termination Reason: Namespace ASSERTIOND, Code 0x8badf00d
Triggered by Thread: 0
Filtered syslog:
None found
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x0000000183563de8 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x0000000183563c60 mach_msg + 72
2 CoreFoundation 0x0000000183aa6e40 __CFRunLoopServiceMachPort + 196
3 CoreFoundation 0x0000000183aa4908 __CFRunLoopRun + 1568
4 CoreFoundation 0x00000001839c4da8 CFRunLoopRunSpecific + 552
5 GraphicsServices 0x00000001859aa020 GSEventRunModal + 100
6 UIKit 0x000000018d9e4758 UIApplicationMain + 236
7 AijouNetto 0x00000001008a851c main + 410908 (AppDelegate.swift:17)
8 libdyld.dylib 0x0000000183455fc0 start + 4
这个类的实现:
class EKNBackgroundTaskManager {
let backgroundDQ = DispatchQueue.global(qos: .background)
var backgroundUpdateTask: UIBackgroundTaskIdentifier!
init(withName: String) {
self.backgroundUpdateTask = UIApplication.shared.beginBackgroundTask(withName: withName) {}
}
func runBackgroundTask(withCode: @escaping (_ cH: @escaping () -> Void) -> Void)
{
backgroundDQ.async {
withCode() {
self.endBackgroungTask()
}
}
}
func endBackgroungTask() {
if backgroundUpdateTask != nil && backgroundUpdateTask != UIBackgroundTaskInvalid {
UIApplication.shared.endBackgroundTask(backgroundUpdateTask)
backgroundUpdateTask = UIBackgroundTaskInvalid
}
}
}
有什么建议可以在应用程序进入后台模式时修复这个错误?
【问题讨论】:
-
您好,请您添加异常断点 (stackoverflow.com/a/17802942/2370587) 并使用 Xcode 暂停的代码更新您的帖子
-
@Maximelc:此崩溃处于后台模式,调试时不显示崩溃日志
-
你能提供一些你操作线程的代码吗?使用 GCD (Grand Central Dispatch) 也许?
-
您的 AppDelegate.swift(靠近第 17 行)可能有助于提示您面对这个问题
-
DispatchQueue.main.async { self.resultsNewspaper = DatabaseManager.shareInstance.getNewspaperLatest() self.resultsNewspaperRegion = DatabaseManager.shareInstance.getNewspaperRegion() self.tbvCity.rowHeight = self.view.layer.bounds。 size.height / 8 self.tbvCity.reloadData() self.ColNewspaper.reloadData() }
标签: ios swift grand-central-dispatch