在我的应用程序中,我创建并使用一个普通的持久存储:
- (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相同)
这里的问题可能是什么?我如何解决这个问题?