如何从ABPeoplePicker获取用户选择的电子邮件地址? [英] How Do I Obtain A User Selected Email Address From ABPeoplePicker?
本文介绍了如何从ABPeoplePicker获取用户选择的电子邮件地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Stackoverflow上的其他人发布了一种从联系人列表中获取用户选择的电话号码的方法.可以对电子邮件地址进行处理,如果可以,该怎么办?这是代码:
Someone else here on Stackoverflow posted a way to obtain a user selected phone number from the contacts list. Could be done for email addresses and if so, how do I do it? Here is the code:
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier
{
if (property == kABPersonPhoneProperty) {
ABMultiValueRef multiPhones = ABRecordCopyValue(person, kABPersonPhoneProperty);
for(CFIndex i = 0; i < ABMultiValueGetCount(multiPhones); i++) {
if(identifier == ABMultiValueGetIdentifierAtIndex (multiPhones, i)) {
CFStringRef phoneNumberRef = ABMultiValueCopyValueAtIndex(multiPhones, i);
CFRelease(multiPhones);
NSString *phoneNumber = (__bridge NSString *) phoneNumberRef;
CFRelease(phoneNumberRef);
_contactNumber.text = [NSString stringWithFormat:@"%@", phoneNumber];
}
}
}
[self dismissViewControllerAnimated:YES completion:nil];
return NO;
}
以下是该帖子的链接: 您如何获取个人电话号码从通讯录中获取?
Here is the link to the post: How do you get a persons phone number from the address book?
推荐答案
如下实现
- (BOOL)peoplePickerNavigationController:
(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person
property:(ABPropertyID)property
identifier:(ABMultiValueIdentifier)identifier
{
ABMultiValueRef emails = ABRecordCopyValue(person, property);
CFIndex ix = ABMultiValueGetIndexForIdentifier(emails, identifier);
CFStringRef email = ABMultiValueCopyValueAtIndex(emails, ix);
NSLog(@"%@", email); // do something with the email here
if (email) CFRelease(email);
if (emails) CFRelease(emails);
[self dismissViewControllerAnimated:YES completion:nil];
return NO;
}
这篇关于如何从ABPeoplePicker获取用户选择的电子邮件地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文