如何从iOS中的地址簿检查和检索更改/新添加的联系人详细信息? [英] how to check and retrieve changed/newly added contact details from address book in iOS?

查看:187
本文介绍了如何从iOS中的地址簿检查和检索更改/新添加的联系人详细信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用中,我收到了所有地址簿数据。但是,当我下次启动应用程序时,我只想在地址簿中检索已修改/新添加的联系人。

In my app I am getting all address book data. But when I start app next time I just want to retrieve modified/newly added contacts in address book.

您能告诉我任何可能的方法吗?

Can you please suggest me any possible ways?

谢谢。

推荐答案

从iOS 9开始,您可以将课程注册到observ CNContactStoreDidChangeNotification

From iOS 9 you can register your class to observ CNContactStoreDidChangeNotification:

Obj-C代码:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addressBookDidChange:) name:CNContactStoreDidChangeNotification object:nil];

然后:

-(void)addressBookDidChange:(NSNotification*)notification
{
  //Handle event here...
}

Swift代码:

NSNotificationCenter.defaultCenter().addObserver(
    self,
    selector: "addressBookDidChange:",
    name: CNContactStoreDidChangeNotification,
    object: nil)

然后:

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


$ b rel =noreferrer>联系框架参考


成功执行保存后,联系人商店发布
CNContactSto reDidChangeNotification通知默认的
通知中心。如果你缓存任何Contacts框架对象,你需要通过它们的标识符来重新获取这些对象,或者用
重新获取用于最初获取它们的谓词,然后
释放缓存的对象。请注意,缓存的对象是陈旧的,但
无效。

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.

这篇关于如何从iOS中的地址簿检查和检索更改/新添加的联系人详细信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆