iOS在阵列中获取所选联系人的电子邮件地址 [英] iOS Getting selected contacts' email address in array

查看:125
本文介绍了iOS在阵列中获取所选联系人的电子邮件地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要做的是向用户显示人物选择器,让他选择他想要的所有联系人,最后将所有这些联系人的电子邮件地址放入阵列中。
最好只显示通过电子邮件发送给用户的联系人。

What I'm trying to do is show the people picker to the user, make him select all the contacts he wants, and finally get all those contacts' email addresses in an array. The best would be showing only contacts with email to the user.

到目前为止,我唯一能做的就是提供人员选择器此代码:

Until now the only thing I've been able to do is presenting the people picker with this code:

ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
     picker.peoplePickerDelegate = self;
     [self presentModalViewController:picker animated:YES];

然后我尝试使用此代码获取所选联系人的电子邮件:

Then I was trying to use this code to get the selected contacts' email:

- (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person {

ABMultiValueRef multi = ABRecordCopyValue(person, kABPersonEmailProperty);
[email addObject:(__bridge NSString*)ABMultiValueCopyValueAtIndex(multi, 0)];
[self dismissModalViewControllerAnimated:YES];

return YES;
}

但是一旦我选择联系人,选择器就会消失,所以我不知道怎么继续。
此外,当我选择一个联系人时,我在控制台中得到这个:

But the picker is going away as soon as I select a contact, so I don't know how to continue. Moreover, right when I select a contact I get this in the console:

"Unbalanced calls to begin/end appearance transitions for 
<ABMembersViewController: 0xa1618c0>."

任何帮助都将不胜感激。

Any help would be appreciated.

推荐答案

我不确定你是否曾解决过你的问题,但如果其他人发现这个帖子,也许会帮助他们。
我从ABPeoplePickerNavigationController收到的电子邮件是删除

I am not sure if you ever solved your problem but if anyone else finds this post maybe it will help them. What I did to get an email from the ABPeoplePickerNavigationController was to remove

[self dismissModalViewControllerAnimated:YES];

来自

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person;

然后我用这个来获取电子邮件并解雇控制器

and then I am using this to get the email and dismiss the controller

- (BOOL)peoplePickerNavigationController(ABPeoplePickerNavigationController*)peoplePicker
  shouldContinueAfterSelectingPerson:(ABRecordRef)person
                            property:(ABPropertyID)property
                          identifier:(ABMultiValueIdentifier)identifier
{
    if (kABPersonEmailProperty == property)
    {
        ABMultiValueRef multi = ABRecordCopyValue(person, kABPersonEmailProperty);
        NSString *email = (__bridge NSString *)ABMultiValueCopyValueAtIndex(multi, 0);
        NSLog(@"email: %@", email);
        [self dismissModalViewControllerAnimated:YES];
        return NO;
    }
    return YES;
}

它允许用户选择特定的电子邮件并解散控制器而不会出现任何错误。

It allows the user to select a specific email and dismisses the controller without any errors.

这篇关于iOS在阵列中获取所选联系人的电子邮件地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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