我的应用程序连接了 Crashlytics,大约 9% 的用户(接近 1000 人)遇到了我无法复制的崩溃。在崩溃的特定行中,我将我的托管对象上下文传递给一个函数,该函数使用它来查找数据。
使用依赖项注入(inject),我能够使用在我的 AppDelegate 中创建的托管对象上下文来实例化我的主视图 Controller 。任何需要托管对象上下文的类都会从这个主视图 Controller 中注入(inject)。下面是我在 Crashlytics 仪表板中获得的堆栈跟踪。感谢任何帮助我弄清楚我能做什么。
Crashed: com.apple.main-thread 0 MyApp 0x10008f47c specialized CalendarService.parseCalendarForMeetings(from : [EKEvent]?) -> [Meeting]? (CalendarService.swift:96) 1 MyApp 0x10006dbf4 specialized MeetingViewController.(launchCalendarService() -> ()).(closure #1) (MeetingViewController.swift:188) 2 MyApp 0x100071e64 partial apply for MeetingViewController.(launchCalendarService() -> ()).(closure #1) (MeetingViewController.swift) 3 MyApp 0x1000a5950 thunk (MeetingListMenuViewController.swift) 4 libdispatch.dylib 0x1806fabb8 _dispatch_block_async_invoke_and_release + 100 5 libdispatch.dylib 0x1806ee9a0 _dispatch_client_callout + 16 6 libdispatch.dylib 0x1806f35e8 _dispatch_main_queue_callback_4CF + 996 7 CoreFoundation 0x1817e50c8 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12 8 CoreFoundation 0x1817e2ce4 __CFRunLoopRun + 1572 9 CoreFoundation 0x181712da4 CFRunLoopRunSpecific + 424 10 GraphicsServices 0x18317d074 GSEventRunModal + 100 11 UIKit 0x1879cdc9c UIApplicationMain + 208 12 MyApp 0x10005b3cc main (AppDelegate.swift:27) 13 libdyld.dylib 0x18072159c start + 4
EDIT:
This is the line of code (line 96 per the stack trace) that appears to be the problem. The MOC is not optional in the CalendarService class nor the CalendarUtility class.
Inside CalendarUtility, the MOC is used to read data only.
let calendarUtil = CalendarUtility(title: event.title, location: event.location, notes: event.notes, managedObjectContext: managedObjectContext)
最佳答案
您可能遇到了竞争条件,并且受影响的用户往往拥有更快或更慢的设备,这会暴露问题。
可以引用以下SO post其中讨论了添加调试设置以检查 CoreData 正在使用的线程。如果操作发生在后台线程上,那么您很可能会崩溃。
关于ios - 我无法重现的用户可能导致 CoreData 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47394736/