尝试在模态视图中使用MFMailComposeViewController

时间:2012-08-20 03:27:23

标签: ios modalviewcontroller mfmailcomposeviewcontroller

我已经从我的基于地图的应用程序成功实现了模态视图控制器,该应用程序使用部分卷曲过渡在地图下方显示选项面板。

从这里开始,我想实现一个允许用户使用MFMailComposeViewControl通过电子邮件与我联系的按钮。我已经实现了下面的代码,但每次点按按钮时应用程序都会崩溃。调用presentModalView。

我知道这个问题必须与试图在另一个上面调用模态视图有关,但我似乎无法弄清楚如何解决。

以下是崩溃消息:

  

* 断言失败 - [UIWindowController转换:fromViewController:toViewController:target:didEndSelector:],   /SourceCache/UIKit_Sim/UIKit-1914.84/UIWindowController.m:188

- (IBAction)sendSupportMail:(id)sender{

    // log this in the debugger 
    NSLog(@"You hit the send support mail button.");


    // dismiss the page curled options view
    [self dismissModalViewControllerAnimated:YES];    


    // check to see if email is available; if so, compose message
    if ([MFMailComposeViewController canSendMail])
    {
        MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];

        mailer.mailComposeDelegate = self;

        [mailer setSubject:@"Subject here"];

        NSArray *toRecipients = [NSArray arrayWithObjects:@"first@mail.com", @"second@mail.com", nil];
        [mailer setToRecipients:toRecipients];

        NSString *emailBody = @"Body Copy";
        [mailer setMessageBody:emailBody isHTML:NO];

         [self presentModalViewController:mailer animated:YES];
        NSLog(@"Present Mailer Called");

        [mailer release];
    }
    else
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure"
                                                        message:@"Your device doesn't support the composer sheet"
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles: nil];
        [alert show];
        [alert release];
    }

}

0 个答案:

没有答案