我没有发现苹果的文档对于实际使用人员选择器获取数据非常有帮助,并且互联网上似乎没有太多其他信息:(我认为我需要在此功能中获取电子邮件:
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier
{
}
我可以在那里输入什么来获取所选人员的电子邮件?
Kal 的答案实际上是不准确的 - 即因为“ABMultiValueCopyValueAtIndex”采用索引而不是标识符。
标识符值是静态的(如枚举)
- “家庭电子邮件”始终为“0”
- “工作电子邮件”始终为“1”。
因此,当所选人员仅存储 1 封电子邮件(即“工作电子邮件”)时,它会崩溃。由于标识符是“1”,但我们需要索引“0”。
幸运的是,我们可以使用以下方法来获取索引:
int index = ABMultiValueGetIndexForIdentifier(emails, identifier);
Code:
if (property == kABPersonEmailProperty) {
ABMultiValueRef emails = ABRecordCopyValue(person, property);
NSString *count = [NSString stringWithFormat:@"Count: %d Identifier: %d", ABMultiValueGetCount(emails), identifier];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"alert" message:count delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
if(ABMultiValueGetCount(emails) > 0)
{
int index = ABMultiValueGetIndexForIdentifier(emails, identifier);
CFStringRef emailTypeSelected = ABMultiValueCopyLabelAtIndex(emails, index);
CFStringRef emailTypeSelectedLocalized = ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(emails, index));
CFStringRef emailValueSelected = ABMultiValueCopyValueAtIndex(emails, index);
self.lblEmailType.text = (NSString *) emailTypeSelected;
self.lblEmailTypeLocalized.text = (NSString *) emailTypeSelectedLocalized;
self.lblEmailValue.text = (NSString *) emailValueSelected;
}
[ self dismissModalViewControllerAnimated:YES ];
return NO;
}
return YES;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)