我正试图从可可的一个ABPerson对象中得到这个国家。
我所做的是:
NSString *country = [person valueForProperty:kABAddressCountryKey];我在控制台上看到这个:
-ABPerson值40属性:国家-未知财产。此警告将仅显示每个未知属性一次,每个会话。
获取人的organizationName(kABOrganizationProperty)、firstName (kABFirstNameProperty)和lastName (kABLastNameProperty)工作。
有什么想法吗?
发布于 2013-08-06 13:00:36
正如键kABAddressCountryKey所暗示的,它表示一个地址的值。由于person可以有多个地址(表示为字典),因此必须循环这些地址才能得到国家:
ABMultiValueRef addressesRef = ABRecordCopyValue(personRef, kABPersonAddressProperty);
for (int i = 0; i < ABMultiValueGetCount(addressesRef); i++)
{
CFDictionaryRef oneAddressRef = ABMultiValueCopyValueAtIndex(addressesRef, i);
NSString *country = CFRetain(CFDictionaryGetValue(oneAddressRef, kABPersonAddressCountryCodeKey));
// Do fancy things with country...
CFRelease(country);
CFRelease(oneAddressRef);
}
CFRelease(addressesRef);还没有最终测试,但它应该是那样工作的。还可以考虑核心基础内存管理。
https://stackoverflow.com/questions/18080422
复制相似问题