草庐IT

iOS - CNContactStoreDidChangeNotification 通知细节差异

coder 2024-01-22 原文

如何获取iPhone通讯录的最新变化

我即将在我的 iOS 应用程序中集成联系人框架,并希望在外部(由其他应用程序或用户)更改联系人(在联系人中添加/编辑字段)时收到通知。我找到了 CNContactStoreDidChangeNotification 并想知道它是否会以有意义的形式带来联系人卡片中究竟发生了什么变化和/或关于哪个联系人发生了变化的信息。

这里找不到

最佳答案

目前,CNContactStoreDidChangeNotification 不提供更改。因此,如果您有一些缓存的联系人,则必须在收到通知时重新获取它们。

-(void)registerForCNContactStoreDidChangeNotification {
   if (!self.hasRegisteredForNotifications) {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(storeDidChange:) name:CNContactStoreDidChangeNotification  object:nil];
        self.hasRegisteredForNotifications = YES;
   }
}

- (void)deviceContactsDidChange:(NSNotification *)notification {
// notification.userInfo can be nil

// need to fetch all contacts with enumerateContactsWithFetchRequest to get all contacts or
// refresh the cached contacts with unifiedContactsMatchingPredicate
}

Apple says

If you cache the fetched contacts, groups, or containers, you need to refetch these objects (and release the old cached objects) when CNContactStoreDidChangeNotification is posted.

关于iOS - CNContactStoreDidChangeNotification 通知细节差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53510196/

有关iOS - CNContactStoreDidChangeNotification 通知细节差异的更多相关文章

随机推荐