gpt4 book ai didi

cocoa - 获取 ABPerson 属性的标签名称

转载 作者:行者123 更新时间:2023-12-03 17:32:10 26 4
gpt4 key购买 nike

我想获取 ABPerson 对象属性的所有标签名称。例如:记录 ABPerson 定义了三个电话号码:Mobile、Other、Work。我使用 labelAtIndex 方法来获取标签名称,但返回的字符串包含用字符 $!!$ 包裹的所需值。我得到的不是仅返回“Mobile”,而是这些“_$!<”换行字符。

我有以下代码:

//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]);
}

在日志中我得到以下内容:

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

有人可以指出我如何获取不带特殊字符的属性的标签名称吗?

最佳答案

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

// 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);
}

关于cocoa - 获取 ABPerson 属性的标签名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8965608/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com