这是我的代码:
- (void)sendMail:(id)sender{
// Email Subject
NSString *emailTitle = @"Test Email";
// Email Content
NSString *messageBody = @"Learning iOS Programming"; // Change the message body to HTML
// To address
NSArray *toRecipents = [NSArray arrayWithObject:@"khi_nakhan@yahoo.com"];
MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:emailTitle];
[mc setMessageBody:messageBody isHTML:YES];
[mc setToRecipients:toRecipents];
// Present mail view controller on screen
[self presentViewController:mc animated:YES completion:NULL];
}
- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
switch (result)
{
case MFMailComposeResultCancelled:
NSLog(@"Mail cancelled");
break;
case MFMailComposeResultSaved:
NSLog(@"Mail saved");
break;
case MFMailComposeResultSent:
NSLog(@"Mail sent");
break;
case MFMailComposeResultFailed:
NSLog(@"Mail sent failure: %@", [error localizedDescription]);
break;
default:
break;
}
// Close the Mail Interface
[self dismissViewControllerAnimated:YES completion:NULL];
}
答案 0 :(得分:3)
您无法从Simulator
发送邮件。您需要从Mail Account
设置Settings
才能执行此操作,而Simulators Settings
中无法使用Devices
,{{1}}仅提供{{1}}。
答案 1 :(得分:0)
您无法从模拟器发送电子邮件,因为邮件设置选项不可用。使用已配置邮件的实际iPhone / iPad,然后测试您的应用。