1

Xcode で次のメッセージが表示されます。

    The provided ubiquity name is already in use., 
NSURL=file://localhost/var/mobile/Applications/6C748748-9689-4F40-B8D7-
CDE8CA280FF8/Documents/SharedCoreDataStores/138F8194-DCC7-4D66-859B-
B2C35BDF2984/iCloudStore.sqlite

このファイル (iCloudStore.sqlite) の場所を見つけるにはどうすればよいですか? ~/Library/Containers と ~/Library/Mobile Documents を試しました。

ありがとう

4

1 に答える 1

6

あなたはそれを見つけることができます

NSURL *DocumentsURL = [[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask].lastObject;

NSURL *tempURL = DocumentsURL;
tempURL = [tempURL URLByAppendingPathComponent:@"sharedCoreDataStores"];
tempURL = [tempURL URLByAppendingPathComponent:@"138F8194-DCC7-4D66-859B-B2C35BDF2984"];
tempURL = [tempURL URLByAppendingPathComponent:@"iCloudStore.sqlite"];
NSURL *iCloudStoreURL = tempURL;

iCloudStoreURL はあなたが望むものです。このストアは、iCloud デモ コードを使用してコア データから作成します。右?

このストア URL を[coordinator addPersistentStore]関数に渡しました。


Core Data で iCloud を使用する場合、2 つの場所と 1 つの名前に注意する必要があります。

1.ストアURL

iCloudストアの実ファイルで、すべてのデータをローカルフォルダーに保存します。すべてのデバイスにはストア ファイルがあります。iCloudからデータを自動転送します。

iCloud ストアを追加するときは、このストアの URL を[coordinator addPersistentStore]関数に渡します。

次に、ストア ファイルがその URL に配置されます。

これは、documentsDirectory のサブディレクトリのようなローカル フォルダーにあります。

for example: 
[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask].lastObject URLByAppendingComponent:@"iCloudStore"];

または他のディレクトリ。私の選択は

[[[NSFileManager defaultManager] URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask].lastObject URLByAppendingComponent:@"iCloudStore"];

2. iCloud CoreData コンテンツ URL

この URL は iCloud コンテナー (または「ユビキタス コンテナー」というコード名) にあります。コア データ コンテンツの変更を記録するためにのみ使用されます。

クラウドで考えてください。[NSFileManager URLForUbiquityContainer:nil]その雲の位置です。

iCloud CoreData Content URLこのユビキタス コンテナのすべての iCloud コア データ データベース転送ログに使用されます。(異なるアプリの異なるコア データ データベースは、おそらく同じユビキタス コンテナーにあり、ログはすべてこの に保存されますcontentURL。)

iCloud Store を追加するためのオプションを設定するときに、次の URL を渡します。

 NSDictionary *cloudOptions =
 @{  NSMigratePersistentStoresAutomaticallyOption:@(YES),
 NSInferMappingModelAutomaticallyOption      :@(YES),
 NSPersistentStoreUbiquitousContentNameKey   :self.iCloudCoreDataContentName,
 NSPersistentStoreUbiquitousContentURLKey    :self.iCloudCoreDataContentURL}

この URL は、iCloud コンテナのサブディレクトリである必要があります[[NSFileManager URLForUbiquityContainer:nil] URLByAppendingComponent:@"CoreDataLogs"]

このプロパティは options ではオプションです。省略した場合、iCloud CoreData Content URL は になります[NSFileManager URLForUbiquityContainer:nil]

3. iCloud CoreData コンテンツ名

コア データ データベースの一意の名前を指定します。すべての iCloud ストアに必要です。iCloud ストアごとに異なる名前を付ける必要があります。

iCloud Store を追加するためのオプションを設定するときに、この名前を渡します。

 NSDictionary *cloudOptions =
 @{  NSMigratePersistentStoresAutomaticallyOption:@(YES),
 NSInferMappingModelAutomaticallyOption      :@(YES),
 NSPersistentStoreUbiquitousContentNameKey   :self.iCloudCoreDataContentName,
 NSPersistentStoreUbiquitousContentURLKey    :self.iCloudCoreDataContentURL}
于 2012-12-27T15:44:07.437 に答える