本文介绍了如何在iphone地址簿中搜索特定的电话号码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一款使用bonjour连接到另一部iphone的应用程序。它的一个功能是当我连接到另一台设备时,它会自动检查我是否有其他人的电话号码。所以我的问题是如何检查我的地址簿中是否有其他设备提供的电话号码?

I am developing an app that connects to another iphone using bonjour. One of its features is when I connect to the other device it will automatically check if I have the other persons phone number. So my problem is how do I check my address book for the phone number provided by the other device?

推荐答案

这是一个提取的示例从我的一个地址簿方法。我没有通过电话号码进行搜索,但这可以让您了解如何向前推进您的需求:

Here's an example extracted from one of my address book methods. I wasn't searching by phone number but this gives you an idea have how to move forward with what you need:

- (void) scanAddressBookSample
    {
    NSUInteger i;
    NSUInteger k;

    ABAddressBookRef addressBook = ABAddressBookCreate();
    NSArray *people = (NSArray *) ABAddressBookCopyArrayOfAllPeople(addressBook);

    if ( people==nil )
        {
        NSLog(@"NO ADDRESS BOOK ENTRIES TO SCAN");
        CFRelease(addressBook);
        return;
        }

    for ( i=0; i<[people count]; i++ )
        {
        ABRecordRef person = (ABRecordRef)[people objectAtIndex:i];

        //
        // Phone Numbers
        //
        ABMutableMultiValueRef phoneNumbers = ABRecordCopyValue(person, kABPersonPhoneProperty);
        CFIndex phoneNumberCount = ABMultiValueGetCount( phoneNumbers );

        for ( k=0; k<phoneNumberCount; k++ )
            {
            CFStringRef phoneNumberLabel = ABMultiValueCopyLabelAtIndex( phoneNumbers, k );
            CFStringRef phoneNumberValue = ABMultiValueCopyValueAtIndex( phoneNumbers, k );
            CFStringRef phoneNumberLocalizedLabel = ABAddressBookCopyLocalizedLabel( phoneNumberLabel );    // converts "_$!<Work>!$_" to "work" and "_$!<Mobile>!$_" to "mobile"

            // Find the ones you want here
            //
            NSLog(@"-----PHONE ENTRY -> %@ : %@", phoneNumberLocalizedLabel, phoneNumberValue );

            CFRelease(phoneNumberLocalizedLabel);
            CFRelease(phoneNumberLabel);
            CFRelease(phoneNumberValue);
            }
        }

    [people release];
    CFRelease(addressBook);
    }

这篇关于如何在iphone地址簿中搜索特定的电话号码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 10:32