首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >获取ABPerson属性的标签名

获取ABPerson属性的标签名
EN

Stack Overflow用户
提问于 2012-01-22 23:19:02
回答 1查看 2K关注 0票数 0

我想获取ABPerson对象属性的所有标签名。例如: record ABPerson定义了三个电话号码:移动电话号码、其他电话号码、工作电话号码。我使用labelAtIndex方法获取标签名,但返回的字符串包含用字符$!$包装的所需值。而不是只返回“移动”,我得到了这些"_$!<“包装字符。

我有以下代码:

代码语言:javascript
复制
//person object points to ABPerson record from addressBook
ABMultiValue *phoneNumbers = [person valueForProperty:kABPhoneProperty];

NSUInteger count = [phoneNumbers count];

for (int i = 0; i < count; i++) {
    NSLog(@"Phone numbers label: %@ value: %@", [phoneNumbers labelAtIndex:i], [phoneNumbers valueAtIndex:i]);        
}

在日志中,我得到以下信息:

代码语言:javascript
复制
2012-01-23 01:14:04.234 FixMyAddressBook[3667:707] Phone numbers label: _$!<Mobile>!$_ value: +327382738273
2012-01-23 01:14:04.370 FixMyAddressBook[3667:707] Phone numbers label: _$!<Work>!$_ value: +3293829328

有人能给我指点一下吗?如果没有特殊的字符,我怎样才能得到属性的标签名称?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-04-23 06:03:34

据我所知,您需要获得该项的本地化标签,您需要确保使用正确的引用代码。

代码语言:javascript
复制
// Grab the right property first
ABMutableMultiValueRef phoneNumbers = ABRecordCopyValue(person, kABPersonPhoneProperty);
CFIndex phoneNumberCount = ABMultiValueGetCount(phoneNumbers);

for(int k = 0; k < phoneNumberCount; k++)
        {

        //Get phone number label by iterating across this
            CFStringRef phoneNumberValue = ABMultiValueCopyValueAtIndex( phoneNumbers, k );

CFStringRef phoneNumberLabel = ABMultiValueCopyLabelAtIndex(phoneNumbers, i);
            CFStringRef phoneNumberLocalizedLabel = ABAddressBookCopyLocalizedLabel( phoneNumberLabel );    
// converts "_$!<Work>!$_" to "work" and "_$!<Mobile>!$_" to "mobile"
//do whatever you want to do here
//release your references
        CFRelease(phoneNumberLocalizedLabel);
CFRelease(phoneNumberValue);
}
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8965608

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档