【问题标题】:Remove Core Data from iCloud fails从 iCloud 中删除核心数据失败
【发布时间】:2014-04-06 14:27:10
【问题描述】:

我正在尝试使用[NSPersistentStoreCoordinator removeUbiquitousContentAndPersistentStoreAtURL:options:error:] 从 iCloud 中删除核心数据。 但我得到奇怪的输出:

__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"}

什么意思?

如何避免?我正在研究 iCloud 禁用/启用功能。详情HERE

更新:

  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];

【问题讨论】:

  • 有没有可能有一个实时持久存储协调器引用该持久存储?
  • 问题解决了吗?
  • 您发送哪些选项作为参数?为您的问题添加更多信息。
  • @TomHarrington,不知道如何检查。
  • @orkenstein 如果您正在使用 MagicalRecord,您应该在 removeUbiquitousContentAndPersistentStoreAtURL 之前调用 [MagicalRecord cleanUp];,这样您就可以确定 nothig 在删除之前保留了存储。

标签: ios objective-c core-data icloud nspersistentstore


【解决方案1】:

通常(在 iOS7 之前),您从 [fileManager URLForUbiquityContainerIdentifier:nil]; 获取 ubiquitousContentURL 值 并将其作为名为 NSPersistentStore UbiquitousContentURLKey 的选项传递,这就是 iCloud 知道将所有数据保存在 iCloud 帐户中的位置的方式。

在 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 session 207 以清楚地了解这些内容。

【讨论】:

    【解决方案2】:

    NSCocoaErrorDomain 错误 513 在 FoundationErrors.h 中定义为 NSFileWriteNoPermissionError。您没有写入该位置所需的权限。

    如果托管对象上下文仍在使用受此存储支持的对象,则可能会发生这种情况。上下文正在积极使用正在移动的文件,这会导致 NSFileCoordinator 冲突。有两件事试图同时访问具有写权限的文件。

    【讨论】:

    • 是的,我明白了。但它必须在该文件夹中可用。或者如何获得访问权限?
    • @orkenstein 我建议改进您的问题,因为您肯定想知道如何成功删除无处不在的内容,而不是找到错误 513 描述?
    • 不知道为什么这被否决了,因为最初的问题是“这是什么意思?”。
    • 谢谢@quellish!明天我会写下整个流程来最终澄清我的问题。感谢您的回复!
    • @quellish 请检查整个源并发出stackoverflow.com/questions/22422283/…
    【解决方案3】:

    removeUbiquitousContentAndPersistentStoreAtURL:options:error: 方法会删除用户的所有本地和云数据——这可能不是您想要的。相反,请将您的商店迁移到磁盘上的新位置,并使用 NSPersistentStoreRemoveUbiquitousMetadataOption 选项和 migratePersistentStore:toURL:options:withType:error: 方法。

    请参阅 iCloud 核心数据编程指南中的Removing an iCloud-enabled Persistent Store禁用 iCloud 持久性

    【讨论】:

    • 如果我真的想在 beta 测试时擦除所有无处不在的内容怎么办?
    • @purrrminator 在这种情况下,您确实想使用removeUbiquitousContentAndPersistentStoreAtURL:options:error: 方法。请参阅相同的文档链接,但请查看“重新开始”部分。
    • 好的,迁移 iCloud -> 本地工作。本地 -> iCloud 没有。本地数据被 iCloud 清除。请检查我的SOURCE
    • @orkenstein 您需要创建一个空的 iCloud 存储,获取该存储的 URL,然后在其上迁移本地存储。请参阅developer.apple.com/library/ios/documentation/DataManagement/…中将用户数据迁移到 iCloud 的第一段
    猜你喜欢
    • 2018-06-21
    • 2018-01-08
    • 1970-01-01
    • 1970-01-01
    • 2012-11-07
    • 2020-01-30
    • 2016-11-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多