views:

113

answers:

2

Hi there,

I am having a problem with the AddressBook framework. It all seems to be stemming from ABCopyRecordForUniqueId returning a record with old data.

Example:

I run up the program below in one terminal window - it shows the current data.

I make a change through the address book UI - my program continues to show old data.

I run up another instance of the same program in a new terminal window - it shows the updated data.

I have tried posting on the omnigroup site with no luck :( so any guidance is really appreciated

PS: If you would like to try the code, to get an address book ID you can export a contact as a vCard and open it with a text editor

int main (int argc, const char * argv[])
{   
ABAddressBookRef addressBook = ABGetSharedAddressBook();

while(1)
{
 ABRecordRef addressBookRecord = NULL;

 addressBookRecord = ABCopyRecordForUniqueId(addressBook, CFSTR("4064D587-0378-4DCF-A6B9-D3702F01C94C:ABPerson"));
 CFShow(addressBookRecord);

 CFRelease(addressBookRecord);

 sleep(1);
}

return 0;
}
A: 

I tried your example myself and am seeing the same problem. Out of curiosity, I tried asking for the shared address book inside the loop (in case there was some weirdness going on with the address book singleton) but this made no difference. I checked out the documentation (ABAddressBook C Reference) as well as the higher-level address book framework reference and guide. As far as I can tell, you're doing the right thing.

I'd file this as a bug against the framework.

Joshua Nozzi
A: 

Hi, thanks for the suggestion. I did file a report but it turns out this is expected

Annoying that it wasn't in the docs..

"Engineering has determined that this issue behaves as intended based on the following information:

The address book requires the run loop to be run in order to receive updates from other applications. Instead of sleep(1), use CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1.0, false)."

Thanks, M

Marcus Wood