Address book callback not called

I have an iPhone app that uses AddressBook.framework and uses Core Data to store these contacts. To ensure that I update my own database when the address book is updated (whether via MobileMe or editing in my own app), I subscribe to a notification when the address book is updated. I am calling this on startup:

ABAddressBookRef book = ABAddressBookCreate();
ABAddressBookRegisterExternalChangeCallback(book, addressBookChanged, self);

      

Which (presumably) causes this on any edit. I have ABPersonViewController that allows editing and addressBookChanged will never get called.

void addressBookChanged(ABAddressBookRef reference, CFDictionaryRef dictionary, void *context) {
    // The contacts controller we need to call
    ContactsController *contacts = (ContactsController *)context;

    // Sync with the Address Book
    [contacts synchronizeWithAddressBook:reference];
}

      

Is there any reason it won't get called?

+2


a source to share


1 answer


It turns out that the reason it wasn't called was a simple mistake. I did:

CFRelease(book);

      



After setting the notification. I removed this and now it is being called.

+8


a source







All Articles