Iphone 如何从ABAddressBookRef中提取Country字段?
我无法理解如何访问ABAddressBookRef中地址的属性。我对电话号码没问题:Iphone 如何从ABAddressBookRef中提取Country字段?,iphone,abaddressbook,street-address,country,abmultivalue,Iphone,Abaddressbook,Street Address,Country,Abmultivalue,我无法理解如何访问ABAddressBookRef中地址的属性。我对电话号码没问题: ABMultiValueRef phoneNumberProperty = ABRecordCopyValue(person, kABPersonPhoneProperty); NSArray* phoneNumbers = (NSArray*)ABMultiValueCopyArrayOfAllValues(phoneNumberProperty); CFRelease(phoneNumberProperty
ABMultiValueRef phoneNumberProperty = ABRecordCopyValue(person, kABPersonPhoneProperty);
NSArray* phoneNumbers = (NSArray*)ABMultiValueCopyArrayOfAllValues(phoneNumberProperty);
CFRelease(phoneNumberProperty);
但是,唉。。。我想不出如何处理地址。如果我这样做:
ABMultiValueRef addressProperty = ABRecordCopyValue(person, kABPersonAddressProperty);
NSArray *address = (NSArray *)ABMultiValueCopyArrayOfAllValues(addressProperty);
我得到了看起来像字典的东西,但它是作为数组键入的。如何访问其中的属性?我在网上看到了大量不同的建议,但它们似乎都涉及大约30行代码,只是从字典中抽出一行
有人能帮忙吗?谢谢 对于地址,您会得到一个字典数组,这样您就可以在数组中循环并从每个字典中提取所需的键值:
ABMultiValueRef addressProperty = ABRecordCopyValue(person, kABPersonAddressProperty);
NSArray *address = (NSArray *)ABMultiValueCopyArrayOfAllValues(addressProperty);
for (NSDictionary *addressDict in address)
{
NSString *country = [addressDict objectForKey:@"Country"];
}
CFRelease(addressProperty);
您也可以直接通过ABMultiValueRef
循环,而不是首先将其转换为NSArray:
ABMultiValueRef addressProperty = ABRecordCopyValue(person, kABPersonAddressProperty);
for (CFIndex i = 0; i < ABMultiValueGetCount(addressProperty); i++)
{
CFDictionaryRef dict = ABMultiValueCopyValueAtIndex(addressProperty, i);
NSString *country = (NSString *)CFDictionaryGetValue(dict, kABPersonAddressCountryKey);
CFRelease(dict);
}
CFRelease(addressProperty);
ABMultiValueRef addressProperty=ABRecordCopyValue(person,kABPersonAddressProperty);
对于(CFIndex i=0;i
Perfecto回答。出于某种原因,我没有看到这是一系列字典。谢谢