我正在尝试向联系人列表中的联系人发送电子邮件。我正在使用一个ABPeoplePickerNavigationController
. 用户选择联系人的电子邮件后,会发生以下情况:
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier {
if(property == kABPersonEmailProperty){
[self dismissModalViewControllerAnimated:YES];
ABMultiValueRef emails = ABRecordCopyValue(person, property);
int index = ABMultiValueGetIndexForIdentifier(emails, identifier);
NSString *emailValueSelected = (__bridge NSString*)ABMultiValueCopyValueAtIndex(emails, index);
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setSubject:@"the subject"];
[controller setMessageBody:@"Hello there" isHTML:NO];
[controller setToRecipients:[[NSArray alloc] initWithObjects:emailValueSelected, nil]];
if (controller){
[self presentModalViewController:controller animated:YES];
}
return NO;
}
return YES;
}
该emailValueSelected
变量具有正确的电子邮件值,并且所有代码似乎都可以毫无问题地执行(甚至是if(controller){...}
语句的主体)。
问题是没有任何反应,电子邮件控制器从未显示。我已经尝试过[self presentViewController:controller animated:YES completion:nil]
和[self presentModalViewController:controller animated:YES];
。
我在我的应用程序的另一部分使用完全相同的代码来发送电子邮件并且它工作正常,所以我猜它与人员选择器有关。