草庐IT

ios - NSPersistentStoreDidImportUbiquitousContentChangesNotification 返回空

coder 2024-01-17 原文

我在使用 CoreData + iCloud 同步时遇到问题。

有时,通知 NSPersistentStoreDidImportUbiquitousContentChangesNotification 在 Inserted、Updated 和 Deleted 中返回一个空数组。

如果有变化时调用这个通知,为什么返回一个空通知?

谢谢!!!

调用通知的代码:

 - (void)persistentStoreDidChange:(NSNotification*)notification
 {
     DLog(@"Change Detected! Notification: %@", notification.description)

     [__managedObjectContext performBlockAndWait:^(void)
     {
         [__managedObjectContext mergeChangesFromContextDidSaveNotification:notification];

         for(id<CoreDataDelegate>delegate in _delegates)
         {
             if([delegate respondsToSelector:@selector(persistentStoreDidChange)])
                [delegate persistentStoreDidChange];

         }
     }];
 }

最佳答案

它只是有时会这样做。与带有 Core Data 的 iCloud 的许多严重问题相比,这是一个非常小的问题。

收到此通知时,我喜欢做的是首先检查插入、更新和删除的对象,然后除非找到某些东西,否则不要继续进行合并过程。做类似的事情

NSDictionary *userInfo = [notification userInfo];
if (([userInfo objectForKey:NSInsertedObjectsKey] > 0) || 
    ([userInfo objectForKey:NSUpdatedObjectsKey] > 0) || 
    ([userInfo objectForKey:NSDeletedObjectsKey] > 0)) 
{
    // merge...
}

关于ios - NSPersistentStoreDidImportUbiquitousContentChangesNotification 返回空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17741803/

有关ios - NSPersistentStoreDidImportUbiquitousContentChangesNotification 返回空的更多相关文章

随机推荐