I’m having a really strange problem where I am trying to find a contact’s address in iOS 6, and unless the contact has an address labelled “Address”, I can’t find it. Any addresses entered under “Work” or “Home” just don’t appear.
In order to try to figure out this problem, is it possible to take a person record from contacts and just dump every value stored? I’m hoping this will help me find where those “Home” and “Work” addresses are living.
Here’s my code so far:
- (void)setAddressFromPerson:(ABRecordRef)person
{
ABMultiValueRef addresses = ABRecordCopyValue(person, kABPersonAddressProperty);
for (CFIndex j = 0; j<ABMultiValueGetCount(addresses);j++){
CFDictionaryRef dict = ABMultiValueCopyValueAtIndex(addresses, j);
CFStringRef typeTmp = ABMultiValueCopyLabelAtIndex(addresses, j);
CFStringRef labeltype = ABAddressBookCopyLocalizedLabel(typeTmp);
NSString *street = [(NSString *)CFDictionaryGetValue(dict, kABPersonAddressStreetKey) copy];
NSString *city = [(NSString *)CFDictionaryGetValue(dict, kABPersonAddressCityKey) copy];
NSString *state = [(NSString *)CFDictionaryGetValue(dict, kABPersonAddressStateKey) copy];
NSString *zip = [(NSString *)CFDictionaryGetValue(dict, kABPersonAddressZIPKey) copy];
NSString *country = [(NSString *)CFDictionaryGetValue(dict, kABPersonAddressCountryKey) copy];
NSLog(street);
}
It’s a bit difficult to parse visually, but the easiest way to dump everything associated with an
ABPersonRefis to get its vCard representation:(assume proper casting from
NSArray *⇒CFArrayRef, etc)