views:

396

answers:

2

The following code creates me an array of all my contacts in my address book by first name and last name. The problem is, I have one contact that keeps showing up with an empty first name and last name. I can't find that contact in my actual address book. Can anyone suggest how to debug this to figure out the source of the mystery ghost contact?

ABAddressBookRef addressBook = ABAddressBookCreate();
NSArray *peopleArray = (NSMutableArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
NSMutableArray *allNames = [NSMutableArray array];

for (id person in peopleArray) {
 NSMutableString *firstName = [(NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty) autorelease];
 NSMutableString *lastName = [(NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty) autorelease];
 ABMutableMultiValueRef multiValueEmail = ABRecordCopyValue(person, kABPersonEmailProperty);
 if (ABMultiValueGetCount(multiValueEmail) > 0) {
  NSString *email = [(NSString *)ABMultiValueCopyValueAtIndex(multiValueEmail, 0) autorelease];
 }

 if (![firstName length]) {
  firstName = @"";
 }
 if (![lastName length]) lastName = @"";

 [allNames addObject:[NSString stringWithFormat:@"%@ %@", firstName, lastName]];
}

The person type is of type NSCFType. I could easily do something like:

 if (![lastName length] && ![firstName length]) continue;

.. and be done with the problem. I'm curious though what entry in my AddressBook is coming up as a ghost. I've tried introspecting the object with gdb, but can't get anything valuable out of it.

I'd like to see all properties for person, but derefing the object to (ABPerson*) doesn't appear to do it.

I've also tried using CFShow(person) that reveals it to be type CPRecord. Can't find further documentation on that, however.

Is there something in gdb I can do to further inspect this particular person object to see where the source of it is coming from?

+1  A: 

The entry is probably flagged as an organization record, rather than a person record. In this case you'll have to pull out the organization name rather than the first and last name.

Try looking at the properties for:

kABPersonOrganizationProperty, kABPersonKindProperty
rein
Sounds like that might be the problem, I'm guessing the default Apple Computer entry. Any idea how I can inspect the person variable in gdb to see its full contents in memory?
Coocoo4Cocoa
+1  A: 

IT is probably a contact that is only an organization

try looking at these properties

These constants implement the person type property (a property of type kABIntegerPropertyType), which indicates whether a person record represents a human being or an organization.

     const ABPropertyID kABPersonKindProperty;
     const CFNumberRef kABPersonKindPerson;
     const CFNumberRef kABPersonKindOrganization;
Bluephlame