Address Book callback not called

回眸只為那壹抹淺笑 提交于 2020-01-05 03:08:48

问题


I have an iPhone app that makes use of the AddressBook.framework and uses Core Data to store these contacts. In order to make sure I update my own database when the Address Book is updated (whether via MobileMe or editing within my own app), I am subscribing to the notification as to when the Address Book is updating. I call this on startup:

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

Which (supposedly) calls this on any editing. I have an ABPersonViewController which allows editing, and addressBookChanged never seems to 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 for it to not be called?


回答1:


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

CFRelease(book);

After setting the notification. I removed that and it's now getting called.



来源:https://stackoverflow.com/questions/2706641/address-book-callback-not-called

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!