gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 17:37:43 24 4
gpt4 key购买 nike

我在我的应用程序中使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com