问题描述
我试图使用 [NSPersistentStoreCoordinator removeUbiquitousContentAndPersistentStoreAtURL:options:error:]
从iCloud中删除Core Data。
但我得到奇怪的输出:
__ 93+ [NSPersistentStoreCoordinator removeUbiquitousContentAndPersistentStoreAtURL:options:error:] _ block_invoke b $ b CoreData:Ubiquity:无法将内容目录移动到新位置:
file:/// private / var / mobile / Library / Mobile%20Documents /< UBIQUITY_ID> /
New: /// private / var / mobile / Library / Mobile%20Documents / OldUbiquitousContent-mobile〜C9439AD0-1E87-4977-9C68-0674F5E2E93B
错误域= NSCocoaErrorDomain Code = 513无法完成操作
(Cocoa错误513.)UserInfo = 0x181ab790 {NSSourceFilePathErrorKey = / private / var / mobile / Library / Mobile Documents /< UBIQUITY_ID>,
NSUserStringVariant =(
Move
) NSFilePath = / private / var / mobile / Library / Mobile Documents /< UBIQUITY_ID>,
NSDestinationFilePath = / private / var / mobile / Library / Mobile Documents / OldUbiquitousContent-mobile〜C9439AD0-1E87-4977-9C68-0674F5E2E93B ,
NSUnderlyingError = 0x181aab50操作无法完成。不允许操作}
How to avoid it? I'm working on iCloud disable/enable feature. Details HERE
UPDATE:
NSDictionary *iCloudOptions =
[NSDictionary dictionaryWithObjectsAndKeys:kICloudContentNameKey, NSPersistentStoreUbiquitousContentNameKey,
iCloudURL, NSPersistentStoreUbiquitousContentURLKey, nil];
// self.lastICloudStoreURL stores NSPersistentStore.URL after stack setup
BOOL result = [NSPersistentStoreCoordinator removeUbiquitousContentAndPersistentStoreAtURL:self.lastICloudStoreURL
options:iCloudOptions
error:&error];
Normally (before iOS7), you take the ubiquitousContentURL value from [fileManager URLForUbiquityContainerIdentifier:nil];
and pass it as an option called NSPersistentStore UbiquitousContentURLKey
, and this is how iCloud know where to keep all of your data in the iCloud account.
In iOS 7 and Mac OS X we don't need to pass a value for that at all, and Apple call URLForUbiquitous ContainerIdentifier automatically under the hood for you.
So the solution looks like this:
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:kICloudContentNameKey, NSPersistentStoreUbiquitousContentNameKey, nil];
NSURL *storeURL = [NSPersistentStore MR_urlForStoreName:[MagicalRecord defaultStoreName]];
BOOL result = [NSPersistentStoreCoordinator removeUbiquitousContentAndPersistentStoreAtURL:storeURL options:options error:&error];
I suggest you to check WWDC 2013 session 207 to get this things clearly.
这篇关于从iCloud删除Core数据失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!