这是一个非常奇怪的问题!我在屏幕上有一个按钮,当按下时会使用以下代码启动MFMailComposeViewController:
-(IBAction) openComposeEmailScreen:(id) sender {
if([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mailComposeViewController = [[MFMailComposeViewController alloc] init];
mailComposeViewController.mailComposeDelegate = self;
[mailComposeViewController setToRecipients:[NSArray arrayWithObject:@"johndoe@gmail.com"]];
[mailComposeViewController setSubject:@"HelloWorld"];
NSLog(@"%@",_pasteBoard.string);
[mailComposeViewController setMessageBody:_pasteBoard.string isHTML:NO];
[self presentViewController:mailComposeViewController animated:YES completion:nil];
}
}
-(void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
if(error) {
NSLog(@"%@",error.localizedDescription);
}
[self dismissViewControllerAnimated:YES completion:nil];
}
此外,我的视图控制器使用正确的协议:
ViewController ()<MFMailComposeViewControllerDelegate>
我在模拟器上运行它。
答案 0 :(得分:2)
MFMailComposeViewController
。你必须在设备上运行。