Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to check and retrieve changed/newly added contact details from address book in 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?

Thanks.

like image 664
user605003 Avatar asked Dec 15 '11 18:12

user605003


Video Answer


1 Answers

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

Obj-C code:

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

And then:

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

Swift code:

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

And then:

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

as reported in 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.

like image 180
andreacipriani Avatar answered Oct 17 '22 07:10

andreacipriani