通讯簿回调未调用 [英] Address Book callback not called
问题描述
我有一个iPhone应用程序,该应用程序使用AddressBook.framework并使用Core Data来存储这些联系人。为了确保在更新通讯簿时(无论是通过MobileMe还是在我自己的应用程序中进行编辑)更新我自己的数据库,我订阅了有关通讯簿何时更新的通知。我在启动时称其为:
ABAddressBookRef book = ABAddressBookCreate();
ABAddressBookRegisterExternalChangeCallback(book,addressBookChanged,self);
哪个(据说)在任何编辑中都调用它。我有一个允许编辑的ABPersonViewController,并且addressBookChanged似乎从未被调用。 * context){
//我们需要调用
ContactsController的联系人控制器* contacts =(ContactsController *)context;
//与通讯簿同步
[contacts syncizeWithAddressBook:reference];
}
是否有任何理由不予称呼?
原来,没有被调用的原因很简单。我做到了:
CFRelease(book);
设置通知后。我删除了它,现在它被调用了。
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?
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.
这篇关于通讯簿回调未调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!