iphone - iCloud 同步不通过无处不在的容器发送数据

标签 iphone ios core-data ios5 icloud

我在我的应用程序中使用 iCloud 已有一段时间了,最​​近遇到设备拒绝相互通信的问题。或者至少在我开始记录合并发生的方法之前我是这么想的。我的 persistentStoreCoordinator 是按照 previous question of mine 中的描述设置的.

问题如下。在设置我的 managedObjectContext 时,我向它添加了一个观察者来查看 NSPersistentStoreDidImportUbiquitousContentChangesNotification 通知,如下所示:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(mergeChangesFrom_iCloud:) name:NSPersistentStoreDidImportUbiquitousContentChangesNotification object:coordinator];

其中 coordinator 设置为 NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator]

我的iCloud方法如下:

- (void)mergeiCloudChanges:(NSNotification *)note forContext:(NSManagedObjectContext *)moc {
    NSLog(@"insert %@", [[note userInfo] valueForKey:@"inserted"]);
    NSLog(@"delete %@", [[note userInfo] valueForKey:@"deleted"]);
    NSLog(@"update %@", [[note userInfo] valueForKey:@"updated"]);
    [moc mergeChangesFromContextDidSaveNotification:note];

    NSNotification *refreshNotification = [NSNotification notificationWithName:@"RefreshAllViews" object:self userInfo:[note userInfo]];
    [[NSNotificationCenter defaultCenter] postNotification:refreshNotification];
}

- (void)mergeChangesFrom_iCloud:(NSNotification *)notification {
    NSLog(@"merging changes");
    NSManagedObjectContext *moc = [self managedObjectContext];
    [moc performBlock:^{
        [self mergeiCloudChanges:notification forContext:moc];
    }];
}

所以现在我们遇到了实际问题

起初,同步进行得很顺利。来自一台设备的数据被更改,然后该更改出现在另一台设备上。但现在,什么都没有。奇怪的部分是您在 mergeiCloudChanges:forContext: 中看到的那些日志。合并实际上发生了。我看到这触发了。但是合并注释的insertdeleteupdate 部分总是没有内容。所以合并发生了,但是没有数据。对于我的生活,我无法弄清楚这是为什么或如何让它再次正确同步。任何帮助将不胜感激。

注意:我还为我的 NSUbiquitousKeyValueStore 使用了 NSUbiquitousKeyValueStoreDidChangeExternallyNotification 通知(我用它来同步 NSUserDefault 键值),并且这些通知传输和更新完全没有任何问题,这让我更加困惑为什么 persistentStoreCoordinator 通知是空白的。

我真的希望有人以前见过/经历过这种情况,因为在用尽了我能想到的所有途径来独自找到并解决这个问题两周后,我觉得我现在处于停滞状态。

最佳答案

我已经弄明白了。基本上,事务日志似乎已损坏或放错了地方。我重新设计了一种重新同步设备的方法,并将立即发布结果 on a previous question of mine

关于iphone - iCloud 同步不通过无处不在的容器发送数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9346503/

相关文章:

ios - 有什么可靠的方法可以确定某个应用程序是否已在设备上卸载?

ios - 抽象实体上的核心数据关系

iphone - 父 NSManagedObjectContext 在子保存后没有变化,但仅在 Release模式下(在 Debug模式下工作)

iphone - 字符串日期 2011-11-25T21 :17:49-05:00 的日期格式化程序出现问题

swift - 从 CoreData 中删除对象

iphone - iOS应用程序后台下载

ios - 绘制世界地图 - 性能和交互 - iOS

iphone - 如何发布应用程序进行测试

ios - 尝试在我的个人 iPhone 上模拟我的 Xcode 项目

ios - 不同的单元格取决于单元格文本