ios – CoreData:错误:(14)数据库的I / O错误

前端之家收集整理的这篇文章主要介绍了ios – CoreData:错误:(14)数据库的I / O错误前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在XCode中编译和运行使用Core Data的项目时,我遇到了一个我从未见过的错误
2013-09-12 16:59:10.156 myapp[57811:70b] CoreData: error: 
      (14) I/O error for database at /Users/administrador/Library/
         Application Support/iPhone Simulator/7.0/Applications/
         6BA67336-B093-46CF-8B11-E3595409DAC2/myapp.app/database.sqlite.  

         sqlite error code:14,'unable to open database file'

生成此消息的代码是:

psc = [[NSPersistentStoreCoordinator alloc]
                   initWithManagedObjectModel:self.managedObjectModel];
    NSURL *storeURL = [[NSBundle mainBundle] 
                         URLForResource:@"database" withExtension:@"sqlite"];
    [psc addPersistentStoreWithType:NSsqliteStoreType 
             configuration:nil URL:storeURL 
             options:@{NSReadOnlyPersistentStoreOption : @YES} error:NULL];

我尝试过Build-> Clean,删除派生数据,卸载应用程序.

我在发布之前检查了this question,我相信问题是不同的.

注意:sqlite是应用程序的资源

使用调试建议的信息

2013-09-12 17:43:38.341 myapp[58322:70b] CoreData: annotation: Connecting to sqlite database file at "/Users/administrador/Library/Application Support/iPhone Simulator/7.0/Applications/6BA67336-B093-46CF-8B11-E3595409DAC2/myapp.app/database.sqlite"
2013-09-12 17:43:38.360 myapp[58322:70b] CoreData: sql: SELECT Z_VERSION,Z_UUID,Z_PLIST FROM Z_MetaDATA
2013-09-12 17:43:38.363 myapp[58322:70b] CoreData: annotation: Disconnecting from sqlite database due to an error.
2013-09-12 17:43:38.364 myapp[58322:70b] CoreData: error: (14) I/O error for database at /Users/administrador/Library/Application Support/iPhone Simulator/7.0/Applications/6BA67336-B093-46CF-8B11-E3595409DAC2/myapp.app/database.sqlite.  sqlite error code:14,'unable to open database file'
2013-09-12 17:43:38.366 myapp[58322:70b] CoreData: annotation: Disconnecting from sqlite database.

解决方法

既然iOS7上的NDA已被解除,我可以发布为完成我发现的这个问题的解决方法.

iOS7中的核心数据默认使用sqlite中的WAL.

唯一可行的解​​决方案是使用没有WAL的iOS6模拟器创建sqlite并将其导入项目中:

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
    static NSPersistentStoreCoordinator *psc;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken,^{
        psc = [[NSPersistentStoreCoordinator alloc] 
                 initWithManagedObjectModel:self.managedObjectModel];
        NSURL *storeURL = [[NSBundle mainBundle] 
                  URLForResource:@"database" withExtension:@"sqlite"];
        [psc addPersistentStoreWithType:NSsqliteStoreType
                          configuration:nil
                                    URL:storeURL
                                options:@{NSReadOnlyPersistentStoreOption : @YES,NSsqlitePragmasOption: @{@"journal_mode":@"DELETE"}}
                                  error:NULL];
    });
    return psc;
}
原文链接:https://www.f2er.com/iOS/333680.html

猜你在找的iOS相关文章