不确定我是否理解正确。您需要每个字段的区域设置名称 - 例如语言环境翻译,法语、德语等?
一般来说,地址字段不多 - 请参阅:ABPerson.h 头文件:
// Addresses
extern const ABPropertyID kABPersonAddressProperty; // Street address - kABMultiDictionaryPropertyType
extern const CFStringRef kABPersonAddressStreetKey;
extern const CFStringRef kABPersonAddressCityKey;
extern const CFStringRef kABPersonAddressStateKey;
extern const CFStringRef kABPersonAddressZIPKey;
extern const CFStringRef kABPersonAddressCountryKey;
extern const CFStringRef kABPersonAddressCountryCodeKey;
如果您需要字段名称(因为可能存在个人幻想名称;)),请务必使用 ABAddressBookCopyLocalizedLabel,如下所示:
CFStringRef label = ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(multiValue, j));
如果我理解错了,也许你想澄清你的问题。
jimmy
EDIT:
好吧,我仍然不确定我是否正确理解了你的意思,但我会以“两种”方式回答你;)
第一个是您需要通用字段名称(与区域设置无关) - 您可以通过这种方式获取这些名称(在项目的当前区域设置中):代码使用 NSArrays 和 NSDictionaries,具体取决于地址簿卡的条目:
- (void) logAddressBook {
ABAddressBookRef addressBook = ABAddressBookCreate();
NSArray *addresses = (NSArray *) ABAddressBookCopyArrayOfAllPeople(addressBook);
int i;
for(i = 0; i < [addresses count]; i++) {
ABRecordRef record = [addresses objectAtIndex:i];
NSString *firstName = (NSString *)ABRecordCopyValue(record, kABPersonFirstNameProperty);
NSString *lastName = (NSString *)ABRecordCopyValue(record, kABPersonLastNameProperty);
NSLog(@"%@, %@", lastName, firstName);
ABMultiValueRef multiValue = ABRecordCopyValue(record, kABPersonEmailProperty);
int count = ABMultiValueGetCount(multiValue);
int j;
for(j = 0; j < count; j++) {
CFStringRef label = ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(multiValue, j));
NSString *value = (NSString *)ABMultiValueCopyValueAtIndex(multiValue, j);
NSLog(@"Email for %@: %@", label, value);
CFRelease(label);
}
//Get the contact´s addresses
CFTypeRef adressesReference = ABRecordCopyValue((ABRecordRef)record, kABPersonAddressProperty);
CFIndex mvCount = ABMultiValueGetCount(adressesReference);
if (mvCount > 0) {
NSLog(@"Addresses: ");
for (j=0; j < mvCount; j++) {
CFStringRef key = ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(adressesReference, j));
NSDictionary *values = (NSDictionary *)ABMultiValueCopyValueAtIndex(adressesReference, j);
NSLog(@"%@ - ", key);
NSEnumerator *enumerator = [values keyEnumerator];
id innerKey;
while ((innerKey = [enumerator nextObject])) {
/* code that uses the returned key */
NSString *value = (NSString *)[values objectForKey: innerKey];
CFStringRef innerKeyLabel = ABAddressBookCopyLocalizedLabel((CFStringRef)innerKey);
NSLog(@"key: %@ -> value: %@", innerKeyLabel, value);
}
}
}
CFRelease(adressesReference);
}
}
查看日志,您就会了解如何获取您喜欢的所有标签和值 - 只需将代码扩展到您想要的字段即可。
我的答案的另一部分:我想知道您是否只想查看用户可能使用的不同语言作为区域设置的标签。比如法语、德语等。如果你想看到这个(让ABAddressBookCopyLocalizedLabel使用不同的语言)我只在项目的.plist文件中找到了“本地化本机开发区域”。如果你改变这个,翻译就会改变。以用户语言显示标签。
我不确定是否可以通过编程方式更改此设置。如果您知道方法,请告诉我;)
所以,我希望这对你有帮助,喜欢我的正确答案:)
Jimmy