开发者

iPhone AddressBook external callback notification?

开发者 https://www.devze.com 2023-03-20 06:51 出处:网络
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.

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.

  1. I opened my app upto TGTextsInboxController viewController
  2. I pressed home button, my app went in background
  3. nNow i have opened iPhone Contacts, changed any phone number of any person.
  4. Open app again from background to foreground.
  5. 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

0

精彩评论

暂无评论...
验证码 换一张
取 消