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?
a source to share
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;
a source to share