2014-04-06 25 views
2

我試圖使用[NSPersistentStoreCoordinator removeUbiquitousContentAndPersistentStoreAtURL:options:error:]從iCloud中刪除核心數據。 但是我得到了奇怪的輸出:從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

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

有沒有可能存在一個持久存儲協調器,該存儲協調器具有對該持久存儲的引用? –

+0

你解決了這個問題嗎? –

+0

您作爲參數發送了哪些選項?添加更多信息到您的問題。 –

回答

1

NSCocoaErrorDomain錯誤513在FoundationErrors.h定義爲NSFileWriteNoPermissionError。您沒有寫入該位置所需的權限。

如果託管對象上下文仍在使用此存儲支持的對象,則可能發生這種情況。上下文主動使用正在移動的文件,這會導致NSFileCoordinator衝突。有兩件事是試圖同時訪問具有寫入權限的文件。

+0

是的,我明白了。但它必須在該文件夾中可用。 或如何獲得訪問權限? – orkenstein

+0

@orkenstein我建議改善你的問題,因爲你definitley想知道如何成功刪除無處不在的內容,而不是找到錯誤513描述? –

+0

@purrrminator完成! – orkenstein

0

removeUbiquitousContentAndPersistentStoreAtURL:options:error:方法刪除所有用戶的本地和雲數據 - 這可能不是你想要的。而應將商店遷移到磁盤上的新位置,並使用NSPersistentStoreRemoveUbiquitousMetadataOption選項和migratePersistentStore:toURL:options:withType:error:方法。

禁用的iCloud持久Removing an iCloud-enabled Persistent StoreiCloud的編程指南核心數據英寸

+0

如果我真的想擦除所有無處不在的內容,而β測試呢? –

+0

@purrrminator在這種情況下,您確實想使用'removeUbiquitousContentAndPersistentStoreAtURL:options:error:'方法。看到相同的文檔鏈接,但看看「重新開始」部分。 –

+0

好的,遷移iCloud - >本地作品。本地 - > iCloud不。使用iCloud清除本地數據。 請檢查我的[SOURCE](https://github.com/orkenstein/HICloudManager) – orkenstein

2

通常(iOS7之前),你從[fileManager URLForUbiquityContainerIdentifier:nil]; 的ubiquitousContentURL價值,把它作爲一個選項叫做NSPersistentStore UbiquitousContentURLKey,這是怎樣的iCloud知道在哪裏,以保持所有數據的iCloud帳戶。

在iOS 7和Mac OS X中,我們不需要爲此傳遞一個值,並且蘋果會爲您自動調用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清楚地得到這個東西。