1

尝试使用标准迁移更新核心数据时,应用程序崩溃而没有错误消息。它具有所有标准日志消息:

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]);
    } 

它甚至没有达到那个未解决的错误行。

4

1 回答 1

0

也许您遇到了我在此处的回答中描述的相同问题(您修改了模型而没有创建新的模型版本)。

一个很好的帮手可能是在@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);
}

它有助于理解问题。

于 2012-12-14T10:48:41.817 回答