2

我正在尝试创建一个使用 Core Data 的 iCloud 应用程序。为此,我使用了UIManagedDocument. 对于persistentStoreOptions,我NSPersistentStoreUbiquitousContentNameKeyNSPersistentStoreUbiquitousContentURLKey. 正如 Apple 建议的那样,我像这样打开文档:

if ([[NSFileManager defaultManager] fileExistsAtPath:[urlOfDatabase path]])
{
    [_database openWithCompletionHandler:^(BOOL success) { ... }];
}
else
{
    [_database saveToURL:urlOfDatabase
        forSaveOperation:UIDocumentSaveForCreating
       completionHandler:^(BOOL success) { ... }];
}

另外,我注册了NSPersistentStoreDidImportUbiquitousContentChangesNotifications,并在该方法中合并了通知中的上下文。

为了测试应用程序,我使用了 iPad 和 iPhone。当我在一台设备上运行它,添加一些数据并在另一台设备上打开它时,会显示正确的数据。但是,如果我在应用程序在两台设备上运行时添加数据,它要么不会更新(我至少等了 10 分钟一次),要么会在几分钟后更新,但只会出现一大堆错误消息:“项目下载失败。”。

我在设置中错过了什么(希望是显而易见的)吗?

4

0 回答 0