2

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 *context ) {
 [((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 ?

Tariq
  • 9,861
  • 12
  • 62
  • 103

2 Answers2

0

Problem resolved:

I was releasing CFRelease(ab); after notification. As soon as i have commented that line. I am able to get notifications.

Tariq
  • 9,861
  • 12
  • 62
  • 103
  • I Had the same issue - tried to remove the CFRelease but that didn't help...Any idea? I'm working with the simulator as well. – Itay Levin Sep 13 '11 at 16:45
  • you are not getting notification calls in MyAddressBookExternalChangeCallback delegate ? – Tariq Sep 14 '11 at 04:17
  • nope, the callabck is not being called at all. i have tried it both in the simulator and on the real device.. Does my app should be "running in background" for it to work? because i don't have the specific key in the plist configured. but i see that my app is returning to the same situation so i'm guessing the deufult is to run in the background...? – Itay Levin Sep 14 '11 at 08:10
0

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

Community
  • 1
  • 1
ChangUZ
  • 5,380
  • 10
  • 46
  • 64
  • Are you sure this is relevant for when the address book is being updated from the iPhone Address Book ? will this callback will be called? – Itay Levin Sep 13 '11 at 16:52
  • Yes, this code is a part of my app. I did check it works fine. – ChangUZ Sep 14 '11 at 00:22
  • In my sample, @property (non-,ret-) ABAdressNookRef addrssbook; – ChangUZ Sep 14 '11 at 00:24
  • I did use CFRelase(addressbook) in (void)dealloc{} – ChangUZ Sep 14 '11 at 00:25
  • when i tried to add Property i get an error saying it is not an object and can't be used with Nonatomic/retain options. Kind of new-bee here - but all of the functions are getting ABAddressBookRef and not a Pointer (ABAddressBookRef*) so if i define the property as returning the pointer - what should i pass to the other methods? – Itay Levin Sep 14 '11 at 08:38
  • Ok, got the callback to be called- the problem was that i put in the register in the controller and not in the delegate of the app. But now my problem is how to parse the callback values- i got the address book ref, and CFDictionary Ref - which will contain the changes made to the address book? – Itay Levin Sep 14 '11 at 08:56
  • Oh sorry not retain... @property (nonatomic, assign) ABAddressBookRef addressBook; – ChangUZ Sep 15 '11 at 08:27
  • I dont know what chaged. When callback, I re-created addressbook. – ChangUZ Sep 15 '11 at 08:30