3

iCloud経由で同期したいCore Dataデータベースを備えた単一のUIManagedDocumentを持つ非常に単純なiOSアプリを作成しています。アプリを開くと、NSMetaDataQuery をセットアップし、NSMetadataQueryDidFinishGatheringNotification と NSMetadataQueryDidUpdateNotification の通知を受け取ります。それらの 1 つが入ってくると、iCloud ドキュメント ディレクトリにあるファイルの数を確認するメソッドが呼び出されます。存在しない場合は作成され、そのpersistantStoreOptionsが次のメソッドで設定されます

- (void)setPersistentStoreOptionsInDocument:(UIManagedDocument *)document
{
    NSMutableDictionary *options = [NSMutableDictionary dictionary];
    [options setObject:[NSNumber numberWithBool:YES] forKey:NSMigratePersistentStoresAutomaticallyOption];
    [options setObject:[NSNumber numberWithBool:YES] forKey:NSInferMappingModelAutomaticallyOption];

    [options setObject:[document.fileURL lastPathComponent] forKey:NSPersistentStoreUbiquitousContentNameKey];
    [options setObject:[[self iCloudURL] URLByAppendingPathComponent:@"DataLogs"] forKey:NSPersistentStoreUbiquitousContentURLKey];

    document.persistentStoreOptions = options;
}

ファイルは正常に作成されたように見えますが (iCloud ドキュメント ビューアーにリストされていることがわかります)、後でファイルを開くときに、アプリを再起動するか、新しいデバイスで開くときに問題が発生します。

新しい UIManagedDocument を作成し、DocumentMetadata.plist ファイルから NSDictionary を作成して、persistentStoreOptions を作成します。しかし、辞書にあるものを見ると、そこには NSPersistentStoreUbiquitousContentNameKey しかありません。私が使用しているコードは次のとおりです。

NSMetadataItem *item = [self.iCloudQuery resultAtIndex:0];
NSURL *url = [item valueForAttribute:NSMetadataItemURLKey];
url = [self filePackageURLForCloudURL:url]; // gets top level filename
self.accountDatabase = [[UIManagedDocument alloc] initWithFileURL:url];
NSURL *optionsURL = [self.accountDatabase.fileURL URLByAppendingPathComponent:@"DocumentMetadata.plist"];
NSDictionary *options = [NSDictionary dictionaryWithContentsOfURL:optionsURL];
self.accountDatabase.persistentStoreOptions = options;
[self useDocument:self.accountDatabase];

persistStoreOptions の残りの項目が iCloud にアップロードされないようにするために、私が見逃しているステップはありますか?

4

0 に答える 0