代码之家  ›  专栏  ›  技术社区  ›  user387184

在iPhone和iPad之间复制核心数据数据库时,为什么会出现写入错误?

  •  0
  • user387184  · 技术社区  · 16 年前

    在我的应用程序中,我创建并使用一个普通的持久存储:

    - (NSPersistentStoreCoordinator *) persistentStoreCoordinator {
        //  D_IN;   
        if (persistentStoreCoordinator != nil) {
            return persistentStoreCoordinator;
        }
        persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: [self managedObjectModel]];
    
        // Allow inferred migration from the original version of the application.
        NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
                                 [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
                                 [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
    
        NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"Dances005.sqlite"]];
    
    
    
    
        NSError *error = nil;
    
        if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl 
                                                            options:options error:&error]){
            NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
    
    
        }
        //  D_OUT;
    
        return persistentStoreCoordinator;
    

    ……没什么特别的。它包含几个NSdata对象——所有核心数据都符合iPhone和iPad。

    我在iPhone上创建了这个文件,并想把它复制到iPad上。当我在ipad上打开同一个应用程序时,它使用复制的sqlite,并且只要它读取/获取就可以正常工作。一旦我更改了数据并需要重新存储,就会出现以下错误:

    Unresolved error Error Domain=NSCocoaErrorDomain Code=256 UserInfo=0x6a2b7a0 "Operation could not be completed. (Cocoa error 256.)", {
        NSFilePath = "/var/mobile/Applications/294B329D-D287-4012-A551-4E7348624225/Documents/Dances005.sqlite";
        NSUnderlyingException = error during SQL execution : attempt to write a readonly database;
    

    目前我使用iphoneExplorer,只需从iphone->mac->ipad中拖动文件即可。我用ifile检查了rw属性,它们是用户在ipad上的rw。(与iPhone相同)

    这里的问题可能是什么?我如何解决这个问题?

    1 回复  |  直到 16 年前
        1
  •  1
  •   Marcus S. Zarra    16 年前

    苹果不支持iphoneExplorer,也不支持“从iphone拖动文件->mac->ipad”。如果你想在你的iPad应用程序中包含这个文件,那么把它作为包的一部分,或者使用另一种机制来传输这个文件。

    推荐文章