【发布时间】:2018-11-28 00:13:17
【问题描述】:
如何获取 iPhone 通讯录的最新变化
我即将在我的 iOS 应用程序中集成联系人框架,并希望在外部(由其他应用程序或用户)更改联系人(在联系人中添加/编辑字段)时收到通知。我找到了 CNContactStoreDidChangeNotification,想知道它是否会以有意义的形式带来联系人卡片中的确切更改和/或更改联系人的信息。
这里找不到
【问题讨论】:
标签: ios objective-c iphone
如何获取 iPhone 通讯录的最新变化
我即将在我的 iOS 应用程序中集成联系人框架,并希望在外部(由其他应用程序或用户)更改联系人(在联系人中添加/编辑字段)时收到通知。我找到了 CNContactStoreDidChangeNotification,想知道它是否会以有意义的形式带来联系人卡片中的确切更改和/或更改联系人的信息。
这里找不到
【问题讨论】:
标签: ios objective-c iphone
目前,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
}
如果您缓存了获取的联系人、群组或容器,则需要在发布 CNContactStoreDidChangeNotification 时重新获取这些对象(并释放旧的缓存对象)。
【讨论】: