ios - MFMailComposeViewController 不会关闭

标签 ios mfmailcomposeviewcontroller dismiss

在按照向我展示如何实现应用程序内邮件的教程进行操作后,它似乎在取消按钮和发送按钮关闭 View 时失败。

现在我在这里看到了一些评论说我应该实现这个方法:

-(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
[self dismissModalViewControllerAnimated:YES];
}

但这并没有解决问题,无论是在模拟器中还是在我的 iPhone 4 上——虽然消息确实被发送了,但 View 并没有消失。

到目前为止,这是我的代码:

#pragma mark - InApp Mail
- (IBAction)openMail:(id)sender
{
if ([MFMailComposeViewController canSendMail])
{
    MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];


    [mailer setSubject:@"iOS School - MultipleAlertViews"];

    NSArray *toRecipients = [NSArray arrayWithObjects:@"", nil];
    [mailer setToRecipients:toRecipients];

    // Attach an image to the email
    NSString *pathFile01 = @"http://dl.dropbox.com/u/61711378/iOS%20School%20-%20Docs/MultipleAlertViewsVCh.pdf";
    NSURL *pdfURLFile01 = [NSURL URLWithString:pathFile01];
    NSData *pdfDataFile01 = [NSData dataWithContentsOfURL:pdfURLFile01];
    [mailer addAttachmentData:pdfDataFile01 mimeType:@"application/pdf" fileName:@"MultipleAlertViewsVCh.pdf"];

    NSString *pathFile02 = @"http://dl.dropbox.com/u/61711378/iOS%20School%20-%20Docs/MultipleAlertViewsVCm.pdf";
    NSURL *pdfURLFile02 = [NSURL URLWithString:pathFile02];
    NSData *pdfDataFile02 = [NSData dataWithContentsOfURL:pdfURLFile02];
    [mailer addAttachmentData:pdfDataFile02 mimeType:@"application/pdf" fileName:@"MultipleAlertViewsVCm.pdf"];


    NSString *emailBody = 
    @"Hello,<br/><br/>You requested code for this project, which you can now use in XCode <br/><br/> You will find 2 Attachements.<br/>One is the Header file and the other is the Implementation file.<br/><br/>Thank you for using this app, if you find it useful, don't forget to give it a Rating in the App Store.<br/><br/>Kind Regards,<br/>iOS School";


    [mailer setMessageBody:emailBody isHTML:YES];

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

- (void)mailComposeController:(MFMailComposeViewController*)controller    didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
switch (result)
{
    case MFMailComposeResultCancelled:
        NSLog(@"Mail cancelled: you cancelled the operation and no email message was queued.");
        break;
    case MFMailComposeResultSaved:
        NSLog(@"Mail saved: you saved the email message in the drafts folder.");
        break;
    case MFMailComposeResultSent:
        NSLog(@"Mail send: the email message is queued in the outbox. It is ready to send.");
        break;
    case MFMailComposeResultFailed:
        NSLog(@"Mail failed: the email message was not saved or queued, possibly due to an error.");
        break;
    default:
        NSLog(@"Mail not sent.");
        break;
}

// Remove the mail view
[self dismissModalViewControllerAnimated:YES];
}

如你所见,我已经实现了 - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult) 结果错误:(NSError*)error

但它不起作用 - 我还缺少其他任何东西 - 我使用的是 iOS 5.1

干杯杰夫

最佳答案

您已经实现了委托(delegate)方法,但还没有设置委托(delegate):

mailer.mailComposeDelegate = self;

在您创建邮件程序 之后。

关于ios - MFMailComposeViewController 不会关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10345582/

相关文章:

iphone - 在操作表中按下取消按钮时关闭邮件 Controller View

java - 无法在自定义 AlertDialog.Builder 上调用 Dismiss()

ios - UILabel 最小字体大小阴影问题

ios - 仅在 Testflight 构建时应用程序崩溃

ios - 强制其他应用在 iOS 中释放麦克风

ios/xcode : UIAlert Not stopping action and clicking OK crashing app

iphone - 播放错误时关闭 MPMoviePlayerViewController

ios - Swift URLSession 在制​​作 PageView 之前无法正常工作

ios - iOS9 MFMailComposeViewController 的 NavigationBar 中的自定义字体?

swift - MFMailComposeViewController Swift - 将方向模式设置为仅纵向