English 中文(简体)
如何只显示与电话号码的联系?
原标题:How to display only contacts with phone number?

我有接收人的看法。 但是,我只想显示在我接听电话之前有电话号码的接触。

This is how I get the modal view:

-(void)messageWillShowRecipientPicker{
    ABPeoplePickerNavigationController *picker = 
              [[ABPeoplePickerNavigationController alloc] init];
    picker.peoplePickerDelegate = self;

    NSArray *displayedItems = 
                [NSArray arrayWithObject:[NSNumber 
                         numberWithInt:kABPersonPhoneProperty]];

    picker.displayedProperties = displayedItems;
    // Show the picker 
    [self presentModalViewController:picker animated:YES];
    [picker release]; 
}

任何如何这样做的想法?

最佳回答

我对此进行了测试,如果工作的话。 Might have to tweak it ^-^

ABAddressBookRef addressBook = ABAddressBookCreate();
    NSArray *allContacts = [(NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook)autorelease];
    for (int i =0; i < allContacts.count; i++) {
        ABRecordRef person = [allContacts objectAtIndex:i];
        if (person != nil) {
            ABMultiValueRef phones = ABRecordCopyValue(person, kABPersonPhoneProperty);
            if (ABMultiValueGetCount(phones) == 0) {
                CFErrorRef error = nil;
                ABAddressBookRemoveRecord(addressBook, person, &error);
                NSLog(@"Removing %@",(NSString *)ABRecordCopyCompositeName(person));
            }
            CFRelease(phones);
        }
    }
    CFErrorRef saveError = nil;
    ABAddressBookSave(addressBook, &saveError);

    ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
    picker.peoplePickerDelegate = self;
    picker.addressBook = addressBook;

    NSArray *displayedItems = 
    [NSArray arrayWithObject:[NSNumber 
                              numberWithInt:kABPersonPhoneProperty]];

    picker.displayedProperties = displayedItems;

    // Show the picker 
    [self presentModalViewController:picker animated:YES];

    CFRelease(addressBook);
问题回答

您可使用/code>来过滤数据,但您可能需要提出代理反对,以对付地址Book或议定书。

Check out https://github.com/erica/ABContactHelper/blob/master/ABContactsHelper.m for an example of a Protocol for AddressBook and Apple s Predicate information here http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Predicates/Articles/pUsing.html and here http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSPredicate_Class/Reference/NSPredicate.html

Cheers and well luck! (^_^)





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签