persistentStoreCoordinator

persistentStoreCoordinator

本文介绍了iCloud同步不通过无处不在容器发送数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的应用程序中使用iCloud了一段时间,最近有一个设备拒绝互相交谈的问题。或者至少这是我想,直到我开始记录合并发生的方法。我的 persistentStoreCoordinator 按照。



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

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

其中 coordinator code> NSPersistentStoreCoordinator * coordinator = [self persistentStoreCoordinator] 。



我的iCloud方法如下:



- (void)mergeiCloudChanges:(NSNotification *)注意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:@RefreshAllViewsobject: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:中看到的日志中。合并实际发生。我看到这个触发。但插入 delete 更新合并备注都是无内容的。所以合并发生,但没有数据。对于我的生活,我不知道为什么这是或如何让它再次正确同步。



注意:我也使用 NSUbiquitousKeyValueStoreDidChangeExternallyNotification 通知我的 NSUbiquitousKeyValueStore (我用来同步 NSUserDefault 键值),这些通知传输和更新没有任何打嗝,这使我更加不清楚为什么 persistentStoreCoordinator 通知是空白的。



我真的希望有人看到/这之前,因为两个星期耗尽了每一个大道,我可以想到找到并解决这个问题我自己,我觉得我现在处于停滞。

解决方案

我有这个想法。基本上,事务日志似乎已损坏或放错位置。我已经重做了一种方法来resycn设备,并将立即发布结果


I have been using iCloud in my apps for a while now and am recently having an issue where devices refuse to talk to each other. Or at least that's what I thought until I started logging the methods where the merging takes place. My persistentStoreCoordinator is set up as described in a previous question of mine.

The problem is the following. When setting up my managedObjectContext, I add an observer to it to view the NSPersistentStoreDidImportUbiquitousContentChangesNotification notification like follows:

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

where coordinator is the set up as NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator].

My iCloud methods are as follows:

- (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];
    }];
}


So now we have the actual problem

At first, syncing went flawlessly. Data from one device was changed, then that change appeared on the other device. But now, nothing. The curious part is in those logs you see in mergeiCloudChanges:forContext:. The merge actually occurs. I see this triggered. But the insert, delete, and update parts of the merge note are ALWAYS without content. So the merge occurs, but with no data. For the life of me, I cannot figure out why this is or how to get it to sync properly again. Any help would be more than appreciated.

Note: I am also using the NSUbiquitousKeyValueStoreDidChangeExternallyNotification notification for my NSUbiquitousKeyValueStore (which I use to sync the NSUserDefault key-values), and those notifications transfer over and update without any hiccups at all, which confuses me even more as to why the persistentStoreCoordinator notifications are blank.

I truly hope someone has seen/experienced this before because after two weeks exhausting every avenue I can think of to find and fix this on my own, I feel I am now at a standstill.

解决方案

I've got this one figured out. Basically, the transaction logs appeared to be corrupted or misplaced. I have reworked a way to resycn devices and will be posting the results immediately on a previous question of mine

这篇关于iCloud同步不通过无处不在容器发送数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 15:02