Blank field appears on iPhone AddressBook, how to debug?

The following code creates for me an array of all my contacts in my address book by first and last name. The problem is that I have one contact that appears with a blank first and last name. I cannot find this contact in my 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 type of person is of type NSCFType. I could easily do something like:

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

      

.. and deal with this problem. I'm curious, but which entry in my address book fits like a ghost. I've tried introspection on an object with gdb, but can't get anything of value out of it.

I would love to see all the properties for a human, but deleting an object with (ABPerson *) doesn't seem like that.

I have also tried using CFShow (Personality) which shows that it is a CPRecord type. However, no further documentation can be found.

Is there anything in gdb I can do to further check this particular object to see where it is coming from?

0


a source to share


2 answers


The record is probably marked as an organization record, not a person record. In this case, you will have to pull out the organization name, not the first and last name.

Try viewing properties for:



kABPersonOrganizationProperty, kABPersonKindProperty

      

+1


a source


IT is probably a contact that is just an organization

try viewing these properties



These constants implement a property of type person (property of type kABIntegerPropertyType), which indicates whether a person is being written to represent a person or an organization.

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

      

+1


a source







All Articles