CoreData MagicalRecord保存方法在iPhone5上崩溃

时间:2014-08-19 09:01:44

标签: ios objective-c iphone core-data magicalrecord

目前我正在使用MagicalRecord v2.3.0-beta.3 commit:d18e74fe435359238b9593c03e41c1ee0baa0b78框架。我一直在iPhone 5上获得1个崩溃日志(来自Crashlytics)。应用程序仍在开发中。崩溃日志如下所示:

Thread : Crashed: com.apple.main-thread
0  libobjc.A.dylib                0x38eee626 objc_msgSend + 5
1  Foundation                     0x2f06d02d -[NSError dealloc] + 60
2  libobjc.A.dylib                0x38ef3b6b objc_object::sidetable_release(bool) + 174
3  libobjc.A.dylib                0x38ef40d3 (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 358
4  CoreFoundation                 0x2e67d481 _CFAutoreleasePoolPop + 16
5  Foundation                     0x2f0778e3 -[NSAutoreleasePool drain] + 122
6  CoreData                       0x2e4bdfbf -[NSManagedObjectContext save:] + 942
7  MyApp                          0x00162f9f __70-[NSManagedObjectContext(MagicalSaves) MR_saveWithOptions:completion:]_block_invoke15 (NSManagedObjectContext+MagicalSaves.m:82) // here app crashes
8  CoreData                       0x2e5219cd developerSubmittedBlockToNSManagedObjectContextPerform + 88
9  CoreData                       0x2e521b13 -[NSManagedObjectContext performBlockAndWait:] + 114
10 MyApp                          0x00162e51 -[NSManagedObjectContext(MagicalSaves) MR_saveWithOptions:completion:] (NSManagedObjectContext+MagicalSaves.m:116)
11 MyApp                          0x000a2b0d -[SPNCoreDataHandler parseAndSaveDictionaryReturnOperationArray:withSaving:] (SPNCoreDataHandler.m:70)
12 MyApp                          0x00078f21 __102-[SPNApiHandler getAllDataWithDownloadingSuccessBlock:savingSuccessBlock:downloadStatus:failureBlock:]_block_invoke (SPNApiHandler.m:69)
13 MyApp                          0x000795b9 __66-[SPNApiHandler sendGetRequestWithPath:successBlock:failureBlock:]_block_invoke (SPNApiHandler.m:174)
14 libdispatch.dylib              0x393cdd53 _dispatch_call_block_and_release + 10
15 libdispatch.dylib              0x393cdd3f _dispatch_client_callout + 22
16 libdispatch.dylib              0x393d06c3 _dispatch_main_queue_callback_4CF + 278
17 CoreFoundation                 0x2e714641 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
18 CoreFoundation                 0x2e712f0d __CFRunLoopRun + 1308
19 CoreFoundation                 0x2e67d729 CFRunLoopRunSpecific + 524
20 CoreFoundation                 0x2e67d50b CFRunLoopRunInMode + 106
21 GraphicsServices               0x335ec6d3 GSEventRunModal + 138
22 UIKit                          0x30fde871 UIApplicationMain + 1136
23 MyApp                          0x0009c347 main (main.m:16)

这是我写的代码:

注意:为了便于阅读,我删除了此方法的某些部分(这就是为什么方法返回void而不是NSArray的原因。)

- (NSArray *)parseAndSaveDictionaryReturnOperationArray:(NSDictionary *)dictionary withSaving:(BOOL)saveSynchrounously {

    [self truncateAll]; //method which removes all entries in coreData

    /* methods below creates entities from array given in dictionary
       using [NSManagedObject MR_createEntity] method 
       e.g. Contact *contact = [Contact MR_createEntity]; */

    [self saveContacts:dictionary[@"contact"]];
    [self savePeople:dictionary[@"person"]];
    [self saveBuildings:dictionary[@"place"]];
    [self saveSessions:dictionary[@"session"]];
    [self saveLectures:dictionary[@"program"]];
    [self savePartners:dictionary[@"partners"]];
    [self saveSponsors:dictionary[@"sponsors"]];
    [self saveExhibitorsPlans:dictionary[@"exhibitorplan"]];
    [self saveMeetingPlans:dictionary[@"meetingplan"]];
    [self saveOrganizationalInformation:dictionary[@"info"]];

    [[NSManagedObjectContext MR_defaultContext] MR_saveToPersistentStoreAndWait];

    //continue executing method...
}

我还尝试使用[[NSManagedObjectContext MR_defaultContext] MR_saveToPersistentStoreWithCompletion:]方法,但它也崩溃了。

在有人建议的其他Stackoverflow问题中,崩溃可能是由于一次删除,创建并保存到许多实体造成的。在我的情况下,它是大约200个已删除的实体+ 200个新实体。它会导致崩溃吗?

在其他设备(iPhone 4s,iPhone 5s,iPad 2,iPad4,iPad mini)上,它可以正常工作。我有什么想法吗?

1 个答案:

答案 0 :(得分:0)

最后我发现了发生了什么。正如我所说,测试人员没有删除和安装应用程序。出现崩溃,因为数据库架构已更改。也许我应该在开发过程中开始考虑数据库版本,以避免出现这类问题。

感谢任何人的回答。