How do I get a modified event contact notification in iOS?

I want to be notified when there is an insert / update event for iPhone contacts.

Is it possible to receive a notification about my application regarding a specific event with a changed contact?

Just a newbie ... for iOS Swift.

I do not expect complete source code. Just wants to know if this is possible or not, as well as a hint.

Thanks in advance.

+5
source share
3 answers

In iOS, this can be done using -

Register External Change Callback Notification -

ABAddressBookRef ntificationaddressbook = ABAddressBookCreate(); ABAddressBookRegisterExternalChangeCallback(ntificationaddressbook, MyAddressBookExternalChangeCallback, self); 

Implement callback -

 void MyAddressBookExternalChangeCallback (ABAddressBookRef ntificationaddressbook,CFDictionaryRef info,void *context) { // called when there is any change in AddressBook } 

For more information, you can refer to this link -

Detect what has been changed from ABAddressBookRegisterExternalChangeCallback

+6
source

From iOS 9, you can register your class to observe CNContactStoreDidChangeNotification

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

And then:

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

as indicated in the link reference information

After the save is successful, the contact store sends a notification message to CNContactStoreDidChangeNotification, the default notification center. If you cache any contact wireframe objects, you must restore these objects either by their identifiers or using the predicates that were originally used to retrieve them, and then release the cached objects. Please note that cached objects are outdated, but not invalid.

EDIT:

Note that the address book and address book user interface frameworks are now out of date.

+17
source

You can implement KeyValue Observers observevalueforkeypath to get notified of the change status of selected items

0
source

Source: https://habr.com/ru/post/1215903/


All Articles