CoreData: error: (14) I/O error for database

后端 未结 2 747
醉梦人生
醉梦人生 2021-01-02 11:17

When compiling and running in the XCode a project using Core Data I\'m getting an error I never saw before:

 2013-09-12 16:59:10.156 myapp[57811         


        
2条回答
  •  [愿得一人]
    2021-01-02 11:58

    Now that the NDA on iOS7 has been lifted I can post for the sake of completion the workaround I found for this problem.

    The Core Data in iOS7 uses by default WAL in the sqlite.

    The only solution that did work was to create the sqlite using iOS6 simulator without WAL and import it in the project:

    - (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;
    }
    

提交回复
热议问题