无法在设备之间进行iCloud同步



我有一个使用核心数据和集成iCloud的应用程序。该应用程序适用于添加和删除具有核心数据的数据。但是当涉及到iCloud时,只有添加新对象是有效的。当我删除一个设备中的一个对象时,它不会在另一个设备上更新。

这是我在核心数据中删除的代码:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
NSManagedObjectContext *context = [self managedObjectContext];
Watchlist *stockToDelete = [self.fetchedResultsController objectAtIndexPath:indexPath];
[context deleteObject:stockToDelete];
NSError *error = nil;
if (![context save:&error]) {
    NSLog(@"Error! %@", error);
}
}
}

这是我使用iCloud合并策略的代码:

- (void)mergeChangesFromiCloud:(NSNotification *)notification {
NSManagedObjectContext* moc = [self managedObjectContext];
NSDictionary *noteInfo = [notification userInfo];
[moc performBlock:^{
NSMutableDictionary *mergingPolicyResult = [NSMutableDictionary dictionary];
[mergingPolicyResult setObject:noteInfo[NSInsertedObjectsKey]
                        forKey:NSInsertedObjectsKey];
[mergingPolicyResult setObject:noteInfo[NSUpdatedObjectsKey]
                        forKey:NSUpdatedObjectsKey];
[mergingPolicyResult setObject:[NSSet set] // Exclude deletions
                        forKey:NSOverwriteMergePolicy];
NSNotification *saveNotification =
[NSNotification notificationWithName:notification.name
                              object:self
                            userInfo:mergingPolicyResult];
[moc mergeChangesFromContextDidSaveNotification:saveNotification];
[moc processPendingChanges]; 
}]; 
}

那么,有人可以帮助我吗?

谢谢。

尝试只使用这一行

[moc mergeChangesFromContextDidSaveNotification:notification];

不确定为什么要修改通知。

最新更新