我遇到了一个非常奇怪的问题,我试图在 iOS 6 中查找联系人的地址,除非联系人的地址标记为“地址”,否则我找不到它。在“工作”或“家庭”下输入的任何地址都不会出现。
为了尝试解决这个问题,是否可以从联系人中获取一个人的记录,然后转储所有存储的值?我希望这会帮助我找到那些“家庭”和“工作”地址所在的位置。
到目前为止,这是我的代码:
- (void)setAddressFromPerson:(ABRecordRef)person
{
ABMultiValueRef addresses = ABRecordCopyValue(person, kABPersonAddressProperty);
for (CFIndex j = 0; j<ABMultiValueGetCount(addresses);j++){
CFDictionaryRef dict = ABMultiValueCopyValueAtIndex(addresses, j);
CFStringRef typeTmp = ABMultiValueCopyLabelAtIndex(addresses, j);
CFStringRef labeltype = ABAddressBookCopyLocalizedLabel(typeTmp);
NSString *street = [(NSString *)CFDictionaryGetValue(dict, kABPersonAddressStreetKey) copy];
NSString *city = [(NSString *)CFDictionaryGetValue(dict, kABPersonAddressCityKey) copy];
NSString *state = [(NSString *)CFDictionaryGetValue(dict, kABPersonAddressStateKey) copy];
NSString *zip = [(NSString *)CFDictionaryGetValue(dict, kABPersonAddressZIPKey) copy];
NSString *country = [(NSString *)CFDictionaryGetValue(dict, kABPersonAddressCountryKey) copy];
NSLog(street);
}
最佳答案
从视觉上解析有点困难,但转储与 ABPersonRef
关联的所有内容的最简单方法是获取其 vCard 表示:
ABPersonRef person = ...;
CFDataRef data = ABPersonCreateVCardRepresentationWithPeople(@[person]);
NSString *vcard = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
(假设从 NSArray *
⇒ CFArrayRef
等正确转换)
关于objective-c - 在 iOS6 中记录为联系人存储的每个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13653993/