views:

30

answers:

0

I'm writing this iphone application where I integrate with AddressBook. I allow users to select, create and edit addressbook entries. When I select an address I verify that all the required fields are filled in and that the Country is available in the Dictionary of address data, and if not I look it up by CountryCode:

ABMultiValueRef addressRef = ABRecordCopyValue(person, kABPersonAddressProperty);
CFIndex addressIndex = ABMultiValueGetIndexForIdentifier(addressRef, identifier);

addressData = (NSMutableDictionary *) ABMultiValueCopyValueAtIndex(addressRef, addressIndex);       

if (!CFDictionaryContainsKey((CFDictionaryRef) addressData, @"Country"))
{
    NSString *countryCode  = [addressData objectForKey: @"CountryCode"];
    NSString *country = [[NSLocale currentLocale] displayNameForKey:NSLocaleCountryCode value:countryCode];

    if (!country)
    {
        NSLog(@"Unknown country code? %@", [addressData objectForKey: @"CountryCode"]);
        [addressData setObject: @"Unknown!" forKey: @"Country"];
    } else {
        [addressData setObject: country forKey: @"Country"];
    }
}

The thing is, I've been getting some reports that my app is reporting that a Country is missing from the address, even though Contacts.app shows the proper country for the address. I've investigated the value returned by ABMultiValueCopyValueAtIndex and sure enough: there's only Street, City and ZIP code in the dictionary. When a user changes the label to which the address belongs a few times, the issue seems to go away.

Has anyone ever seen this situation before? Does anyone have any tips on how I might resolve this issue?