iPhone AddressBook external callback notification?
In viewDidLoad, I have subscribed to notifications to get external callback notifications. I dont know why I am not getting notifications in my app if i have changed anything in my iphone contacts.
I am doing in this way:
ab=ABAddressBookCreate();
ABAddressBookRegisterExternalChangeCallback(ab, MyAddressBookExternalChangeCallback, self);
And I have defined this in same controller
void MyAddressBookExternalChangeCallback ( ABAddressBookRef addressBook, CFDictionaryRef info, void *con开发者_StackOverflow中文版text ) {
[((TGTextsInboxController *) context) addressBookHasChanged];
}
How can I debug this ? I have tried in this way in Simulator.
- I opened my app upto TGTextsInboxController viewController
- I pressed home button, my app went in background
- nNow i have opened iPhone Contacts, changed any phone number of any person.
- Open app again from background to foreground.
- No notifications has been reflected. Neither degugger pointer hit to this method "MyAddressBookExternalChangeCallback"
Something wrong ?
Problem resolved:
I was releasing CFRelease(ab);
after notification. As soon as i have commented that line. I am able to get notifications.
Use addressBook call back.
void ABAddressBookRegisterExternalChangeCallback (
ABAddressBookRef addressBook,
ABExternalChangeCallback callback,
void *context
);
My Sample - Register (After creating addressBookRef)
ABAddressBookRegisterExternalChangeCallback(addressBook, addressBookChanged, self);
My Smaple - Do Something & Unregister
void addressBookChanged(ABAddressBookRef abRef, CFDictionaryRef dicRef, void *context) {
NSLog(@"!!!!!Address Book Changed!");
//Do Something You Need. (Recreate addressbook or Reload UITableView data.)
ABAddressBookUnregisterExternalChangeCallback(abRef, addressBookChanged, context);
}
My answer: Iphone addressbook
精彩评论