views:

180

answers:

1

I have discovered something strage when accessing the Addressbook-API on iOS4.

//address
ABMutableMultiValueRef address = ABMultiValueCreateMutable(kABDictionaryPropertyType);
CFStringRef keys[5];
CFStringRef values[5];

keys[0] = kABPersonAddressStreetKey;    
keys[1] = kABPersonAddressCityKey;  
keys[2] = kABPersonAddressStateKey; 
keys[3] = kABPersonAddressZIPKey;   
keys[4] = kABPersonAddressCountryCodeKey;   
values[0] = (CFStringRef)restaurant.street; 
values[1] = (CFStringRef)restaurant.city;   
values[2] = (CFStringRef)restaurant.federalState;
values[3] = (CFStringRef)restaurant.zip_code;
values[4] = (CFStringRef)[restaurant.country_iso lowercaseString];
CFDictionaryRef aDict = CFDictionaryCreate(
                            kCFAllocatorDefault,
                            (void *)keys, 
                            (void *)values,
                            5,
                            &kCFCopyStringDictionaryKeyCallBacks,
                            &kCFTypeDictionaryValueCallBacks
                        );  

ABMultiValueIdentifier identifier;  
ABMultiValueAddValueAndLabel(address, aDict, kABWorkLabel, &identifier);    
CFRelease(aDict);
ABRecordSetValue(aRecord, kABPersonAddressProperty, address, anError);
CFRelease(address);

It seems that the value for kABPersonAddressCountryCodeKey is simply ignored. No matter which country iso-code is provided, the country in the address book will always be the country set for the Region Format in the settings-menu. The strange thing is, that everything works fine and as expected on OS3.1.3. But (compiled for 3.1.3 and 4.0) executed on an iOS4-Device creates the described problem.

Is this a bug in iOS4 or did i miss something? I couldn't find any information on changes in the Addressbook-API, and it seems noone else has discovered similar problems yet. Am I doing something wrong or is it iOS4?

A: 

apparently, i have encountered the same issue today. Setting the kABPersonAddressCountryCodeKey to a supported keycode did not actually set the Record's country correctly (defaulted to the US).

Emanuel