ABAddressBookRegisterExternalChangeCallback in the controller not called on done edit

1.5k views Asked by At

I have a couple of questions related to address book and ABAddressBookRegisterExternalChangeCallback.

addressBook = ABAddressBookCreateWithOptions(NULL, &error);

I am opening a new contact record with allowsEditing = YES add it to

ABAddressBookAddRecord(addressBook, aContact,&anError)

ABAddressBookRegisterExternalChangeCallback(addressBook, changed, (__bridge void *)(self));

all this done NOT in app delegate (I have read one of the post stating that this may be the reason for callback not being called)

Does it have to be done in app delegate? Is the problem because this contact was just created? However, if I attempt too call app delegate to:

ab = ABAddressBookCreateWithOptions(NULL, &error);
ABAddressBookRegisterExternalChangeCallback(appABChanged, ab, (__bridge void *)(self));

the app crashes.

Is there any other way to get notified when DONE button is clicked in the controller? I am not concerned about AB changes, I just want to use built in contact editing functionality , all I really care about is ABRecordRef.

I guess what I am trying to say is really what I need is ABPersonViewController notification of DONE click button and receiving modified ABrecordRef hopefully with a flag if it was actually modified.

1

There are 1 answers

1
Ankit Brahmbhatt On

First you register e.g In didFinishingLunching you register using this function:

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

When you change native contact's record you receive notification using this function:`

void addressBookChanged(ABAddressBookRef addressBook, CFDictionaryRef info, void *context) {
    NSLog(@"Recevied notification");
}