ios:应用程序尝试在目标上显示nil模态视图控制器 [英] ios: Application tried to present a nil modal view controller on target

查看:152
本文介绍了ios:应用程序尝试在目标上显示nil模态视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,要求是在UIAlertView的按钮上打开电子邮件编辑器。

I am developing an application,the requirement is to open email composer on a button click of UIAlertView.

从UITextView复制邮件正文中的邮件。我正在使用以下代码片段:

message which is in message body of email is copied from UITextView. i am using following code snipt:

-(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中打开默认邮件编辑器?

but the issue is that i am getting error saying Application tried to present a nil modal view controller on target. how we can open default mail composer in ios 7?

推荐答案

根据Apple的说法,你应该检查 MFMailComposeViewController 能够在发送之前发送您的邮件

As per Apple, You should check is MFMailComposeViewController are able to send your mail just before sending

if ([MFMailComposeViewController canSendMail]) {
     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];
}

参考: Apple Dev url

这篇关于ios:应用程序尝试在目标上显示nil模态视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆