I have iCloud
在我的应用程序中。我已经删除了iCloud
从我的应用程序,但在 ios 6 应用程序崩溃,我收到此消息:
-[NSPersistentStoreCoordinator addPersistentStoreWithType:configuration:URL:options:error:](1055):
CoreData: Ubiquity: Error:
之前使用 iCloud 集成选项添加到协调器的持久存储必须始终使用选项字典中存在的选项添加到协调器。如果您想在不使用商店的情况下使用iCloud
,将数据从iCloud
将文件存储到本地存储中的新存储文件。
我该如何解决这个错误?如何将数据从iCloud
将文件存储到本地存储中的新存储文件?
是的,我也有这个问题。
我想将 iCloud 商店转变为本地商店
解决方案 1:将 ManagedObjects 逐一移动到 localStore。
但如果你有一个很大的数据库,它就会很慢。
所以我昨天找到了第二个解决方案。
解决方案 2:编辑 iCloud 商店的元数据,
并将其保存到新位置。
删除元数据中的“com.apple.coredata.ubiquity.*”键后,
您将获得一家完全本地化的商店。
这是我的解决方案 2 的代码:
已经设置了一些属性:
@property (nonatomic, strong) NSPersistentStoreCoordinator *coordinator;
@property (nonatomic, strong) NSManagedObjectContext *context;
@property (nonatomic, strong) NSPersistentStore *iCloudStore;
//represent the iCloud store already using
//(after [coordinator addPersistentStore] you get this NSPersistentStore)
@property (nonatomic, strong) NSURL *iCloudStoreURL;
//represent the iCloud store real location
//(it is the URL you send to the [coordinator addPersistentStore])
@property (nonatomic, strong) NSURL *iCloudStoreLocalVersionURL;
//represent the location of local version store you want to save
以及迁移方法:
-(void)migrateCloudStoreToLocalVersion
{
if(!self.iCloudStore)
return;
// remove previous local version
[FILE_MANAGER removeItemAtURL:self.iCloudStoreLocalVersionURL
error:nil];
// made a copy from original location to the new location
[FILE_MANAGER copyItemAtURL:self.iCloudStoreURL
toURL:self.iCloudStoreLocalVersionURL
error:nil];
//prepare meta data
NSDictionary *iCloudMetadata = [self.coordinator metadataForPersistentStore:self.iCloudStore].copy;
NSMutableDictionary *localVersionMetadata = iCloudMetadata.mutableCopy;
for(NSString * key in iCloudMetadata){
if([key hasPrefix:@"com.apple.coredata.ubiquity"]){
[localVersionMetadata removeObjectForKey:key];
}
}
//modify iCloud store
[self.coordinator setMetadata:localVersionMetadata forPersistentStore:self.iCloudStore];
[self.coordinator setURL:self.iCloudStoreLocalVersionURL forPersistentStore:self.iCloudStore];
//save to the localVersion location
[self.context save:nil];
//restore iCloud store
[self.coordinator setMetadata:iCloudMetadata forPersistentStore:self.iCloudStore];
[self.coordinator setURL:self.iCloudStoreURL forPersistentStore:self.iCloudStore];
}
然后您可以使用iCloudStoreLocalVersionURL
使用本地版本存储。
您可以使用此本地版本存储作为本地存储,不会出现任何错误。
Note:
注意NSStoreUUIDKey
在元数据中,
您可以选择将其更换为新商店。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)