I am migrating an application from the deprecated Address Book Framework to the new Contacts Framework. The application utilizes ABAddressBookRegisterExternalChangeCallback
to be notified when another application changes a contact.
I am unable to find equivalent functionality in the Contacts Framework. Apple documentation says to use the default notification center with the CNContactStoreDidChangeNotification
notification:
The notification posted when changes occur in another
CNContactStore
.
Taking Apple's advice, my code looks like this:
NSNotificationCenter.defaultCenter().addObserver( self, selector: "contactsChanged:", name: CNContactStoreDidChangeNotification, object: nil)
However, I have found two problems with this approach:
- I am notified for all changes, including those made by my own application.
- Notifications are spurious - I receive many notifications for a single change.
If I log the debug description of the notification when the change was made within my app, I get something like this:
NSConcreteNotification 0x7d3370e0 {name = CNContactStoreDidChangeNotification; userInfo = { CNNotificationOriginationExternally = 1; CNNotificationSourcesKey = ( ); }}
And if the changes are made externally:
NSConcreteNotification 0x7bf7a690 {name = CNContactStoreDidChangeNotification; userInfo = { CNNotificationOriginationExternally = 1; CNNotificationSourcesKey = ( ); }}
As you can see, nothing obvious with which to distinguish them.
Can anyone tell me how to get the same behavior from the Contacts Framework as one can get from ABAddressBookRegisterExternalChangeCallback
?
0 comments:
Post a Comment