6

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.

user605003
  • 75
  • 1
  • 6
  • Possible duplicate of [How to deal with addressbook changes](http://stackoverflow.com/questions/8432234/how-to-deal-with-addressbook-changes/8432391#8432391) – fearmint Dec 15 '11 at 19:01
  • Possible duplicate of [How to get notified in contact changed event in IOS?](https://stackoverflow.com/questions/29208605/how-to-get-notified-in-contact-changed-event-in-ios) – N J Mar 31 '18 at 13:43

2 Answers2

8

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.

andreacipriani
  • 2,519
  • 26
  • 23
0

I wrote a method that checks the address book for updated phone numbers or emails of contacts; specifically only contacts the user added but there's nothing stopping one from extending it to all contacts.

It's called JPContactArchive and the method you'll want to check out is -updateContacts. It should help.

fearmint
  • 5,276
  • 2
  • 33
  • 45
  • first time when i launch app i want retrieve all contacts but at second time i want retrieve only modified and newly added contacts. Now I have taken all contacts in dictionary and all dictionary objects putted into array. – Swapnil Dec 18 '11 at 06:38
  • given link is not working.please provide proper link. – bittu Jul 14 '16 at 10:58