如何阅读电话簿号码标签?

发布于 2024-12-29 21:02:55 字数 1057 浏览 3 评论 0原文

我知道如何从 ABRecordRef 获取电话号码,但我现在想要的是获取号码的类型,即其标签作为字符串:

const CFStringRef kABPersonPhoneIPhoneLabel;
const CFStringRef kABPersonPhoneMainLabel;
const CFStringRef kABPersonPhoneHomeFAXLabel;
const CFStringRef kABPersonPhoneWorkFAXLabel;
const CFStringRef kABPersonPhonePagerLabel;

以下是我获取号码​​的方法:

//get all phone numbers                   
NSArray *phoneNumbersArray = (NSArray*)ABMultiValueCopyArrayOfAllValues(phoneNumberProperty);
NSInteger numbersCounter = 0;
for(numbersCounter = 0; numbersCounter < [phoneNumbersArray count]; numbersCounter++)
{
     NSString currentPhoneNumber = [phoneNumbersArray objectAtIndex:indexPhoneNumber];

      // here i would like to read the type of phone number 
      // NSLog(@"NumberType:%@",numberType);                    
 }

I尝试了各种方法,我已经阅读了 ABPerson Reference,我不知道如何获取电话号码类型?

I know how to get the phone number from an ABRecordRef, but what I want now is to also get the type of the number, i.e. its label as a string:

const CFStringRef kABPersonPhoneIPhoneLabel;
const CFStringRef kABPersonPhoneMainLabel;
const CFStringRef kABPersonPhoneHomeFAXLabel;
const CFStringRef kABPersonPhoneWorkFAXLabel;
const CFStringRef kABPersonPhonePagerLabel;

Here is how I get the numbers:

//get all phone numbers                   
NSArray *phoneNumbersArray = (NSArray*)ABMultiValueCopyArrayOfAllValues(phoneNumberProperty);
NSInteger numbersCounter = 0;
for(numbersCounter = 0; numbersCounter < [phoneNumbersArray count]; numbersCounter++)
{
     NSString currentPhoneNumber = [phoneNumbersArray objectAtIndex:indexPhoneNumber];

      // here i would like to read the type of phone number 
      // NSLog(@"NumberType:%@",numberType);                    
 }

I tried all sorts of things and I've read the ABPerson Reference and I don't know how to get the phone number type?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风为裳 2025-01-05 21:02:55

我已经弄清楚如何读取电话号码的本地化标签

//get all phone numbers
ABMultiValueRef phoneNumberMultiValue = ABRecordCopyValue(currentPerson, kABPersonPhoneProperty);
NSUInteger phoneNumberIndex;
for (phoneNumberIndex = 0; phoneNumberIndex < ABMultiValueGetCount(phoneNumberMultiValue); phoneNumberIndex++) {

    CFStringRef labelStingRef = ABMultiValueCopyLabelAtIndex (phoneNumberMultiValue, phoneNumberIndex);

    NSString *phoneLabelLocalized = (NSString*)ABAddressBookCopyLocalizedLabel(labelStingRef);

    NSString *phoneNumber  = (NSString *)ABMultiValueCopyValueAtIndex(phoneNumberMultiValue, phoneNumberIndex);
    //memory management
    [phoneLabelLocalized release];
    [phoneNumber release];
    CFRelease(labelStingRef);
}

I have figure out how to read the localized label of the phone number

//get all phone numbers
ABMultiValueRef phoneNumberMultiValue = ABRecordCopyValue(currentPerson, kABPersonPhoneProperty);
NSUInteger phoneNumberIndex;
for (phoneNumberIndex = 0; phoneNumberIndex < ABMultiValueGetCount(phoneNumberMultiValue); phoneNumberIndex++) {

    CFStringRef labelStingRef = ABMultiValueCopyLabelAtIndex (phoneNumberMultiValue, phoneNumberIndex);

    NSString *phoneLabelLocalized = (NSString*)ABAddressBookCopyLocalizedLabel(labelStingRef);

    NSString *phoneNumber  = (NSString *)ABMultiValueCopyValueAtIndex(phoneNumberMultiValue, phoneNumberIndex);
    //memory management
    [phoneLabelLocalized release];
    [phoneNumber release];
    CFRelease(labelStingRef);
}
土豪 2025-01-05 21:02:55

下面是一个代码片段,它创建一个人,添加 2 个电话联系人,然后展示如何获取电话属性的标签和值:

ABMutableMultiValueRef multi = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueIdentifier multivalueIdentifier;

ABMultiValueAddValueAndLabel(multi, @"(555) 555-1234",
                             kABPersonPhoneMobileLabel, &multivalueIdentifier);
ABMultiValueAddValueAndLabel(multi, @"(555) 555-2345",
                             kABPersonPhoneMainLabel, &multivalueIdentifier);

ABRecordRef aRecord = ABPersonCreate();

CFErrorRef anError = NULL;

ABRecordSetValue(aRecord, kABPersonPhoneProperty, multi, &anError);

CFRelease(multi);

multi = ABRecordCopyValue(aRecord, kABPersonPhoneProperty);

for (CFIndex i = 0; i < ABMultiValueGetCount(multi); i++)
{
    CFStringRef phoneNumber, phoneNumberLabel;

    phoneNumberLabel = ABMultiValueCopyLabelAtIndex(multi, i);
    phoneNumber      = ABMultiValueCopyValueAtIndex(multi, i);

    NSLog(@"%@ %@", (NSString *) phoneNumberLabel, (NSString *) phoneNumber);

    CFRelease(phoneNumberLabel);
    CFRelease(phoneNumber);
}

CFRelease(aRecord);

CFRelease(multi);

在代码中,它迭代所有多值并提取标签和号码,分别使用 ABMultiValueCopyLabelAtIndexABMultiValueCopyValueAtIndex

Here's a code snippet that creates a person, adds 2 phone contacts and then shows how to get at the label and value for the phone property:

ABMutableMultiValueRef multi = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueIdentifier multivalueIdentifier;

ABMultiValueAddValueAndLabel(multi, @"(555) 555-1234",
                             kABPersonPhoneMobileLabel, &multivalueIdentifier);
ABMultiValueAddValueAndLabel(multi, @"(555) 555-2345",
                             kABPersonPhoneMainLabel, &multivalueIdentifier);

ABRecordRef aRecord = ABPersonCreate();

CFErrorRef anError = NULL;

ABRecordSetValue(aRecord, kABPersonPhoneProperty, multi, &anError);

CFRelease(multi);

multi = ABRecordCopyValue(aRecord, kABPersonPhoneProperty);

for (CFIndex i = 0; i < ABMultiValueGetCount(multi); i++)
{
    CFStringRef phoneNumber, phoneNumberLabel;

    phoneNumberLabel = ABMultiValueCopyLabelAtIndex(multi, i);
    phoneNumber      = ABMultiValueCopyValueAtIndex(multi, i);

    NSLog(@"%@ %@", (NSString *) phoneNumberLabel, (NSString *) phoneNumber);

    CFRelease(phoneNumberLabel);
    CFRelease(phoneNumber);
}

CFRelease(aRecord);

CFRelease(multi);

In the code it iterates over all the multi-values and extracts the label and number as it goes, using ABMultiValueCopyLabelAtIndex and ABMultiValueCopyValueAtIndex respectively.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文