2

を使用してiCloudからCore Dataを削除しようとして[NSPersistentStoreCoordinator removeUbiquitousContentAndPersistentStoreAtURL:options:error:]います。しかし、私は奇妙な出力を得ます:

__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の無効化/有効化機能に取り組んでいます。詳細はこちら

アップデート:

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

3 に答える 3

2

通常 (iOS7 より前)、 から ubiquitousContentURL 値を取得し、[fileManager URLForUbiquityContainerIdentifier:nil]; それを というオプションとして渡し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 セッション 207 を確認することをお勧めします。

于 2014-08-06T14:05:57.890 に答える
1

NSCocoaErrorDomain エラー 513 は、FoundationErrors.h で として定義されていNSFileWriteNoPermissionErrorます。その場所への書き込みに必要なアクセス許可がありません。

これは、管理対象オブジェクト コンテキストが、このストアによってサポートされているオブジェクトをまだ使用している場合に発生する可能性があります。移動中のファイルをコンテキストがアクティブに使用しているため、NSFileCoordinator の競合が発生します。2 つのものが同時に書き込み権限でファイルにアクセスしようとしています。

于 2014-08-05T20:00:25.673 に答える
0

このremoveUbiquitousContentAndPersistentStoreAtURL:options:error:メソッドは、ユーザーのローカル データとクラウド データをすべて削除します。これは、おそらく望んでいないことです。代わりに、ストアをディスク上の新しい場所に移行し、メソッドでNSPersistentStoreRemoveUbiquitousMetadataOptionオプションを使用してください。migratePersistentStore:toURL:options:withType:error:

コア データのiCloud プログラミング ガイドの iCloud対応永続ストアの削除 でiCloud永続性の無効化を参照してください。

于 2014-08-05T20:41:49.840 に答える