DocumentMetada.plist未在iCloud中完成

时间:2012-10-05 01:02:57

标签: ios icloud

我正在创建一个非常简单的iOS应用程序,它将拥有一个带有Core Data数据库的UIManagedDocument,我希望通过iCloud进行同步。当我打开应用程序时,我设置NSMetaDataQuery并获取NSMetadataQueryDidFinishGatheringNotification和NSMetadataQueryDidUpdateNotification的通知。当其中一个进来时,他们会调用一个方法来检查并查看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];

我是否缺少一些阻止persistentStoreOptions中其他项目上传到iCloud的步骤?

0 个答案:

没有答案