从iCloud删除Core数据失败 [英] Remove Core Data from iCloud fails

查看:218
本文介绍了从iCloud删除Core数据失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用 [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操作无法完成。不允许操作}

这是什么意思?

如何避免?我正在使用iCloud禁用/启用功能。此处



更新:



  NSDictionary * iCloudOptions = 
[NSDictionary dictionaryWithObjectsAndKeys:kICloudContentNameKey,NSPersistentStoreUbiquitousContentNameKey,
iCloudURL,NSPersistentStoreUbiquitousContentURLKey,nil];

// self.lastICloudStoreURL存储NSPersistentStore.URL setup
BOOL result = [NSPersistentStoreCoordinator removeUbiquitousContentAndPersistentStoreAtURL:self.lastICloudStoreURL
options:iCloudOptions
error:& error];


解决方案

通常(在iOS7之前),您从 [fileManager URLForUbiquityContainerIdentifier:nil];
,并将它作为一个选项传递 NSPersistentStore UbiquitousContentURLKey ,这就是iCloud如何知道在iCloud帐户中保存您的所有数据。 / p>

在iOS 7和Mac OS X中,我们不需要传递一个值,而Apple会自动调用URLForUbiquitous ContainerIdentifier。



所以解决方案如下:

  NSDictionary * options = [NSDictionary dictionaryWithObjectsAndKeys :kICloudContentNameKey,NSPersistentStoreUbiquitousContentNameKey,nil]; 
NSURL * storeURL = [NSPersistentStore MR_urlForStoreName:[MagicalRecord defaultStoreName]];
BOOL result = [NSPersistentStoreCoordinator removeUbiquitousContentAndPersistentStoreAtURL:storeURL options:options error:& error];

我建议你检查WWDC 2013第207期会议清楚。


I'm trying to remove Core Data from iCloud using [NSPersistentStoreCoordinator removeUbiquitousContentAndPersistentStoreAtURL:options:error:]. But I get strange output:

__93+[NSPersistentStoreCoordinator removeUbiquitousContentAndPersistentStoreAtURL:options:error:]_block_invoke(1982):
CoreData: Ubiquity:  Unable to move content directory to new location:
file:///private/var/mobile/Library/Mobile%20Documents/<UBIQUITY_ID>/    
New: file:///private/var/mobile/Library/Mobile%20Documents/OldUbiquitousContent-mobile~C9439AD0-1E87-4977-9C68-0674F5E2E93B
Error Domain=NSCocoaErrorDomain Code=513 "The operation couldn’t be completed.
(Cocoa error 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 "The operation couldn’t be completed. Operation not permitted"}

What does it mean?

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数据失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆