我正在开发一个应用程序,要求在UIAlertView的按钮点击时打开电子邮件撰写器。
邮件消息体中的消息是从UITextView复制的。我正在使用以下代码片段:
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0)
{
// opening message composer
}
else
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"Test mail"];
[picker setMessageBody:messageBody.text isHTML:YES];
[self presentViewController:picker animated:YES completion:NULL];
}
}
// mail compose delegate
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
[self dismissViewControllerAnimated:YES completion:NULL];
}
但问题在于我收到了一个错误,说应用尝试在目标上呈现一个无效的模态视图控制器。我们该如何在iOS 7中打开默认的邮件撰写器?
canSendMail
后,我们将不得不依赖于设备测试。 - John Pang