gpt4 book ai didi

ios - 从 iCloud 中删除核心数据失败

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:05:43 27 4
gpt4 key购买 nike

我正在尝试使用 [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];

最佳答案

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

关于ios - 从 iCloud 中删除核心数据失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22895357/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com