My application registers a callback once:
notificationAddressBook = ABAddressBookCreate(); ABAddressBookRegisterExternalChangeCallback(notificationAddressBook, MyAddressBookExternalChangeCallback, self);
Then in my callback:
void MyAddressBookExternalChangeCallback (ABAddressBookRef notifyAddressBook,CFDictionaryRef info,void *context) { NSLog(@"in MyAddressBook External Change Callback"); ABAddressBookRevert(notifyAddressBook); CFArrayRef peopleRefs = ABAddressBookCopyArrayOfAllPeopleInSource(notifyAddressBook, kABSourceTypeLocal); CFIndex count = CFArrayGetCount(peopleRefs); NSMutableArray* people = [NSMutableArray arrayWithCapacity:count]; for (CFIndex i=0; i < count; i++) { ABRecordRef ref = CFArrayGetValueAtIndex(peopleRefs, i); ABRecordID id_ = ABRecordGetRecordID(ref); TiContactsPerson* person = [[[TiContactsPerson alloc] _initWithPageContext:[context executionContext] recordId:id_ module:context] autorelease]; NSLog(@"name: %@", [person valueForKey:@"firstName"]); NSLog(@"phone: %@", [person valueForKey:@"phone"]); NSLog(@"modified: %@", [person valueForKey:@"modified"]); [people addObject:person]; } CFRelease(peopleRefs); }
When a new contact is added, the event fires normally, and the data is updated in the first addition, and the second and third. The problem is editing existing contact details.
The first time the event is triggered, the data is correct for the last update (I changed the phone number of one contact in iPhone contacts), then switch to the application and get the latest update. Then I will return to the address book, make another change, switch to my application and get another event. This time the data is outdated, recent changes are not reflected.
I tried to free an instance of ABAddressBookRef and call ABAddressBookCreate() again, but that didn't help either.
Any ideas?
Moshe marciano
source share