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.
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.
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.
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.