尝试使用标准迁移更新核心数据时,应用程序崩溃时没有出现错误消息。它包含所有标准日志消息:
CoreData: sql: INSERT INTO ZENTRY(Z_PK, Z_ENT, Z_OPT, ZLOCATION, ZBOOKMARKED, ZCREATIONDATE, ZENTRYID, ZMESSAGE, ZSECTIONIDENTIFIER, ZTICDSSYNCID, ZVERSION) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
CoreData: sql: COMMIT
CoreData: sql: SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZISINPHOTOLIBRARY, t0.ZLARGETHUMBNAIL, t0.ZMOVIE, t0.ZORIGINALHEIGHT, t0.ZORIGINALIMAGE, t0.ZORIGINALWIDTH, t0.ZSCREENSIZEIMAGE, t0.ZTHUMBNAIL, t0.ZTYPE, t0.ZENTRY, t0.Z_FOK_ENTRY FROM ZMEDIA t0
它持续几秒钟,然后崩溃到主屏幕,没有进一步的日志消息。
崩溃前的代码是:
persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
NSURL *storeUrl = [NSURL fileURLWithPath:storePath];
NSError *error;
NSDictionary *pscOptions = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:NO], NSInferMappingModelAutomaticallyOption,
nil];
然后它在这一行崩溃了:
if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:pscOptions error:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
}
它甚至没有达到未解决的错误行。
答案 0 :(得分:0)
也许你有我在我的回答here中描述的相同问题(你修改了模型而没有创建新的模型版本)。
对你来说,一个很好的帮手可能是@try @catch块中的问题包装线,看看它有什么样的结果:
@try
{
if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:pscOptions error:&error])
{
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
}
}
@catch(NSException* ex)
{
NSLog(@"Exception: %@", ex);
}
它有助于理解问题。