问题描述
我的应用中有 iCloud
。我从我的应用程序中删除了 iCloud
,但在ios 6应用程序崩溃时我收到此消息:
I have iCloud
in my app. I've removed iCloud
from my app, but on ios 6 app crashes and I get this message:
-[NSPersistentStoreCoordinator addPersistentStoreWithType:configuration:URL:options:error:](1055):
CoreData:Ubiquity:错误:
以前使用iCloud集成选项添加到协调器的持久存储必须始终通过选项添加到协调器出现在选项词典中。如果您希望在没有 iCloud
的情况下使用商店,请将数据从 iCloud
商店文件迁移到新的商店文件中本地存储。
CoreData: Ubiquity: Error:
A persistent store which has been previously added to a coordinator using the iCloud integration options must always be added to the coordinator with the options present in the options dictionary. If you wish to use the store without iCloud
, migrate the data from the iCloud
store file to a new store file in local storage.
如何解决此错误?如何将数据从 iCloud
商店文件迁移到本地存储中的新商店文件?
How can I solve this error? How can I migrate the data from the iCloud
store file to a new store file in local storage?
推荐答案
是的,我也有这个问题。
我想将iCloud商店变成本地商店
YES, I have this question too.I want to turn a iCloud store to a local store
但是如果你有一个大型数据库,它会很慢。
But if you have a large database, it will be so slow.
所以我昨天找到了第二个解决方案。
So I found a second solution yesterday.
之后删除元数据中的com.apple.coredata.ubiquity。*键,
您将获得一个完全本地商店。
After you remove "com.apple.coredata.ubiquity.*" keys in metadata, you'll get a fully local store.
以下是解决方案2的代码:
Here is my code for solution 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
使用本地版本商店。
Then you can use the iCloudStoreLocalVersionURL
to using the local version store.
您可以将本地版本商店用作本地商店,不会有任何错误。
You can use this local version store as local store, without any error.
注意:
请注意元数据中的 NSStoreUUIDKey
,
您可以选择将其替换为新商店。
you can optional replace it for the new store.
这篇关于如何将数据从iCloud存储文件迁移到本地存储中的新存储文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!