ios - 如何在 IOS 中的联系人更改事件中得到通知?

标签 ios swift

<分区>

我想在 iPhone 的联系人有插入/更新事件时得到通知。

是否可以向我的应用发送有关发生特定联系人更改事件的通知?

对于 IOS Swift 来说只是一个新手...

我不期待完整的源代码。只是想知道它是否可能并提示。

提前致谢。

最佳答案

从 iOS 9 开始,您可以注册您的类(class)以观察CNContactStoreDidChangeNotification

NSNotificationCenter.defaultCenter().addObserver(
    self,
    selector: #selector(addressBookDidChange),
    name: NSNotification.Name.CNContactStoreDidChange,
    object: nil)

然后:

@objc func addressBookDidChange(notification: NSNotification){     
    //Handle event here...
}

Contacts Framework Reference 中所报告

After a save is successfully executed, the contact store posts a CNContactStoreDidChangeNotification notification to the default notification center. If you cache any Contacts framework objects you need to refetch those objects, either by their identifiers, or with the predicates that were used to originally fetch them, and then release the cached objects. Note that cached objects are stale, but not invalid.

编辑:

请注意,地址簿和地址簿 UI 框架现已弃用。

关于ios - 如何在 IOS 中的联系人更改事件中得到通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29208605/

相关文章:

ios - 如何在 UIDatePicker 中禁用 future 的日期、月份和年份?

ios - liberty lite 越狱检测失败

ios - 约束没有按我的预期工作

ios - UITableView 更新动画已成功,但需要更多详细信息

ios - 从 UICollectionViewCell 到 ViewController 的自动布局约束

c++ - Zlib压缩放大文件

ios - 根据键盘是否可见更改 TextView 的框架

ios - 解析子类实例方法 EXC_BAD_INSTRUCTION

ios - 如何在 Swift 4 中为 UISlider 轨道添加边框颜色?

ios - 触摸时自动滚动到 tableviewcell