我需要一些帮助来弄清楚崩溃报告中可能发生的事情.这对我来说是一个不可重现的问题,但有些用户在发布时会反复遇到这种情况.
当应用程序启动时,我将一个包含NSObjectController的nib加载到ContactsListDisplaySource对象,并将一个NSArrayController加载为了peopleArrayController(它是ContactsListDisplaySource对象中的一个出口). peopleArrayController是从ContactsListDisplaySource refetchArrayController中的数据库中获取联系人列表的内容:
- (void) refetchArrayController { NSError *error = nil; [_peopleArrayController fetchWithRequest:nil merge:NO error:&error]; if (error) { NSLog(@"error in peopleArrayController fetch = %@",error); } }
编辑:请注意,这是从awakeFromNib调用的,并且使用fetch:而不是fetchWithRequest:merge:error返回0行
这有99%的时间可以工作,但我想弄清楚这个崩溃报告中发生了什么.崩溃报告中是否有任何可以解释问题的线索?
Date/Time: 2015-04-22 12:17:17 +0000 OS Version: Mac OS X 10.10.3 (14D136) Report Version: 104 Exception Type: SIGSEGV Exception Codes: SEGV_NOOP at 0x0 Crashed Thread: 0 Thread 0 Crashed: 0 libsqlite3.dylib 0x00007fff8e3770ad sqlite3VdbeHalt + 7741 1 libsqlite3.dylib 0x00007fff8e3bd9c7 sqlite3VdbeExec + 93206 2 libsqlite3.dylib 0x00007fff8e3a53df sqlite3_step + 734 3 CoreData 0x00007fff91126710 _execute + 112 4 CoreData 0x00007fff911389b8 -[NSsqliteConnection fetchResultSet:usingFetchPlan:] + 1880 5 CoreData 0x00007fff91140719 newFetchedRowsForFetchPlan_MT + 2217 6 CoreData 0x00007fff9112cea8 -[NSsqlCore objectsForFetchRequest:inContext:] + 520 7 CoreData 0x00007fff9112c90b -[NSsqlCore executeRequest:withContext:error:] + 299 8 CoreData 0x00007fff911e1389 __65-[NSPersistentStoreCoordinator executeRequest:withContext:error:]_block_invoke + 3945 9 CoreData 0x00007fff911eb5ab gutsOfBlockToNSPersistentStoreCoordinatorPerform + 171 10 libdispatch.dylib 0x00007fff8eb62c13 _dispatch_client_callout + 7 11 libdispatch.dylib 0x00007fff8eb63e5e _dispatch_barrier_sync_f_invoke + 56 12 CoreData 0x00007fff911da5a2 _perform + 194 13 CoreData 0x00007fff9112c5a5 -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 533 14 CoreData 0x00007fff9112adfb -[NSManagedObjectContext executeFetchRequest:error:] + 587 15 AppKit 0x00007fff91ddd745 -[_NSManagedProxy fetchObjectsWithFetchRequest:error:] + 69 16 AppKit 0x00007fff91c1aacc -[NSArrayController(NSManagedController) _performFetchWithRequest:merge:error:] + 62 17 AppKit 0x00007fff91ddcdc3 -[NSObjectController(NSManagedController) fetchWithRequest:merge:error:] + 176 18 Contacts Journal CRM 0x000000010d0d8eb2 -[ContactsListDisplaySource refetchArrayController] (ContactsListDisplaySource.m:57) 19 Contacts Journal CRM 0x000000010d0d8e6e -[ContactsListDisplaySource awakeFromNib] (ContactsListDisplaySource.m:47) 20 CoreFoundation 0x00007fff8c736bdf -[NSSet makeObjectsPerformSelector:] + 223 21 AppKit 0x00007fff917b214d -[NSIBObjectData nibInstantiateWithOwner:options:topLevelObjects:] + 1216 22 AppKit 0x00007fff9198ca0e -[NSNib _instantiateNibWithExternalNa@R_502_338@ble:options:] + 677 23 AppKit 0x00007fff9198c65e -[NSNib _instantiateWithOwner:options:topLevelObjects:] + 143 24 AppKit 0x00007fff9198b957 -[NSViewController loadView] + 272 25 AppKit 0x00007fff9190af03 -[NSViewController _loadViewIfrequired] + 75 26 AppKit 0x00007fff9190ae6d -[NSViewController view] + 30 27 Contacts Journal CRM 0x000000010d021078 -[AppDelegate displayVC:] (AppDelegate.m:496) 28 Contacts Journal CRM 0x000000010d020ff8 -[AppDelegate changeViewControllersWithIndex:] (AppDelegate.m:414) 29 Contacts Journal CRM 0x000000010d01edb6 -[AppDelegate postApplicationDidFinishLaunchingWithNotification:] (AppDelegate.m:130) 30 Contacts Journal CRM 0x000000010d01ec00 -[AppDelegate applicationWillFinishLaunching:] (AppDelegate.m:114) 31 CoreFoundation 0x00007fff8c7e645c __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12 32 CoreFoundation 0x00007fff8c6d6634 _CFXNotificationPost + 3140 33 Foundation 0x00007fff8f33d9d1 -[NSNotificationCenter postNotificationName:object:userInfo:] + 66 34 AppKit 0x00007fff9180cf57 -[NSApplication finishLaunching] + 440 35 AppKit 0x00007fff9180ca21 -[NSApplication run] + 128 36 AppKit 0x00007fff91789354 NSApplicationMain + 1832 37 libdyld.dylib 0x00007fff8d0cd5c9 start + 1
你可能认为这是非常基本的,但也许你可以试试这个:
[_peopleArrayController.managedObjectContext performBlockAndWait: ^{ [_peopleArrayController fetchWithRequest:nil merge:NO error:&error]; }];
我发现在使用核心数据时使用managedObjectContext的performBlock:和performBlockAndWait:方法可以防止我的应用程序挂起.只需查看NSManagedObjectContext类引用https://developer.apple.com/library/ios/documentation/Cocoa/Reference/CoreDataFramework/Classes/NSManagedObjectContext_Class/即可