如何告诉ABPeoplePickerNavigationController仅列出具有电子邮件地址的联系人? [英] How to tell ABPeoplePickerNavigationController to list only contacts that have an email address?

查看:163
本文介绍了如何告诉ABPeoplePickerNavigationController仅列出具有电子邮件地址的联系人?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的用户通过从地址簿中选择联系人的电子邮件来填写电子邮件字段。我不希望他们滚动所有没有设置电子邮件的联系人,所以我想过滤那些有电子邮件地址的联系人。

这是迄今为止我写的代码。我可以找出谁有电子邮件地址,谁没有,但我不能告诉 ABPeoplePickerNavigationController 只列出正确的联系人。这是不可能的,我的意思是我必须通过使用表视图来实现我自己的联系人选择器类,或者这段代码有什么问题吗?

  ABAddressBookRef addressBook = ABAddressBookCreate(); 
NSArray * peopleList =(NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
NSLog(@%ld人存在于地址簿,ABAddressBookGetPersonCount(addressBook));
for(id peopleRecord in peopleList){
ABMultiValueRef mv = ABRecordCopyValue((ABRecordRef)peopleRecord,kABPersonEmailProperty);
CFIndex numberOfAddresses = ABMultiValueGetCount(mv);
if(numberOfAddresses == 0){
CFErrorRef err;
ABAddressBookRemoveRecord(addressBook,(ABRecordRef)peopleRecord,& err);
}
}
[peopleList release];

NSLog(@%ld people have an email,ABAddressBookGetPersonCount(addressBook));

ABPeoplePickerNavigationController * peoplePicker = [[ABPeoplePickerNavigationController alloc] init];
NSNumber * emailProp = [NSNumber numberWithInt:kABPersonEmailProperty];
[peoplePicker setAddressBook:addressBook];
peoplePicker.displayedProperties = [NSArray arrayWithObject:emailProp];
[peoplePicker setPeoplePickerDelegate:self];
[self presentModalViewController:peoplePicker animated:YES];


解决方案

我不相信有办法让iOS做这个过滤。我也是用代码来做的。请注意,您需要查找各种电子邮件地址 - 您必须遍历可以获得的字典。使用这是一个PITA肯定 - 我已经做到了 - 你必须小心,没有内存泄漏。

我所做的是按照您的建议 - 遍历所有联系人,然后使用表格弹出视图,然后选择所需人员的名称。我保持一个协会,所以我知道什么地址与什么名字关联,然后使用系统电子邮件框架,然后填充发送到的地址。

I want my users to fill an email field by selecting a contact's email from their address books. I don't want them to scroll all the contacts whose emails are not set, so I want to filter the ones that have email addresses.

This is the code I've written so far. I can figure out who has an email address and who has not but I couldn't tell the ABPeoplePickerNavigationController to list only the right contacts. Is it impossible to achieve this, I mean do I have to implement my own contact picker class by using a table view or is there something wrong with this piece of code?

ABAddressBookRef addressBook = ABAddressBookCreate();
NSArray *peopleList = (NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
NSLog(@"%ld people exist in the addressBook", ABAddressBookGetPersonCount(addressBook));
for (id peopleRecord in peopleList) {
    ABMultiValueRef mv = ABRecordCopyValue((ABRecordRef)peopleRecord, kABPersonEmailProperty);
    CFIndex numberOfAddresses = ABMultiValueGetCount(mv);
    if(numberOfAddresses == 0) {
        CFErrorRef err;
        ABAddressBookRemoveRecord( addressBook, (ABRecordRef)peopleRecord, &err);
    }
}
[peopleList release];

NSLog(@"%ld people have an email", ABAddressBookGetPersonCount(addressBook));

ABPeoplePickerNavigationController *peoplePicker = [[ABPeoplePickerNavigationController alloc] init];
NSNumber* emailProp = [NSNumber numberWithInt:kABPersonEmailProperty];
[peoplePicker setAddressBook:addressBook];
peoplePicker.displayedProperties = [NSArray arrayWithObject:emailProp];
[peoplePicker setPeoplePickerDelegate:self];
[self presentModalViewController:peoplePicker animated:YES];

解决方案

I do not believe there is a way to get iOS to do this filtering. I do it in code too. Note that you need to look for all kinds of email addresses - you have to iterate through the dictionary that you can get. Working with this is a PITA for sure - I've done it before - and you have to be careful to not have memory leaks.

What I do is as you suggest - iterate through all contact myself, then I pop a view with a table and let then select the names of the people they want. I keep an association around so I know what address is associated with what name, then use the system email framework and then populate the send-to addresses.

这篇关于如何告诉ABPeoplePickerNavigationController仅列出具有电子邮件地址的联系人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆