Lion Address Book Bug in Detail

I was able to track down the root of the problem that I reported on yesterday with PostCheck and Mac OS X Lion. (I would imagine it could affect any Address Book plugins.) This bug is only present in Lion (at least as of 10.7.1), all previous versions of OS X behave as expected.

Here’s how to reproduce the problem:

  1. Create an Address Book record with one or more addresses.
  2. Quit Address Book.
  3. Open Address Book to that same record.
  4. Add a new address.
  5. Use PostCheck on that new address.

The result is that any previously added addresses will be erased, leaving just the newly added address. (It can be reversed using Address Book’s undo, luckily.)

All Apple Address Book plugins get called with this method after a user selects the plugin’s menu item from the context menu:

- (void)performActionForPerson:(ABPerson *)person
identifier:(NSString *)identifier

If I use NSLog() to display the details of “person”, in Lion it does not list any of the existing addresses as being part of the record, just the newly added one. In all previous versions of the OS, it properly lists all the addresses.

The work-around that I came up with is to re-lookup the person from the Address Book database:

NSString *uniqueID = [person uniqueId]; // kABUIDProperty
ABPerson *foundPerson = [[ABAddressBook sharedAddressBook] recordForUniqueId:uniqueID];

“foundPerson” will contain all the addresses, unlike the “person” object that is passed to the plugin to begin with. I don’t understand why this works this way but I’m glad it does until the bug is fixed.