附加截图xcode 4.3时无法关闭电子邮件

时间:2012-03-27 15:27:02

标签: xcode ios5 email-attachments

当我通过电子邮件从我的应用程序发送屏幕截图时,我无法在调用时关闭电子邮件客户端。即使我点击取消也没有任何反应,有人可以告诉我,我做错了。

- (void)btn:(id)sender {


UIGraphicsBeginImageContext(self.view.frame.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

NSData * imageData = UIImageJPEGRepresentation(image, 1.0);

if ( [MFMailComposeViewController canSendMail] ) {
    MFMailComposeViewController * mailComposer = [[[MFMailComposeViewController alloc] init] self];
    mailComposer.delegate = self;
    [mailComposer addAttachmentData:imageData mimeType:@"image/jpeg" fileName:@"attachment.jpg"];



    [self presentModalViewController:mailComposer animated:YES];

}

[self dismissModalViewControllerAnimated:YES];

1 个答案:

答案 0 :(得分:1)

您需要将代理设置为mailComposer.mailComposeDelegate = self;

然后在mail composer委托方法中调用dismiss方法:

- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
    // Do any processing before dismissing
    [self dismissModalViewControllerAnimated:YES];
}