不确定,如果我没听错的话。您需要每个字段的语言环境名称 - 例如语言环境翻译,法语,德语等?
一般来说,地址字段并不多 - 请参阅: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));
如果我弄错了,也许你想澄清你的问题。
吉米
编辑:
好的,我仍然不确定我是否正确,但我会回答“两种”我得到你的方式;)
首先是您想要通用字段名称(与语言环境无关) - 您可以通过这种方式获取那些(在您项目的当前语言环境中):代码使用 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文件中找到了'Localization native development region'。如果你改变它,翻译就会改变。以用户语言显示标签。
我不确定是否可以通过编程方式进行更改。如果你知道方法,请告诉我;)
所以,我希望这能帮助你喜欢我的正确答案:)
吉米