我正在尝试截取屏幕截图,然后使用邮件编辑器通过电子邮件发送该截图。一切工作都很好,但邮件编辑器不会关闭。这篇文章似乎有相同的问题,但是提供的解决方案对我不起作用。 Can't dismiss the email composer view in iPhone?

- (IBAction)Email:(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] autorelease];
    mailComposer.delegate = self;
    [mailComposer setSubject:@"Risk Assessment"];
    [mailComposer addAttachmentData:imageData mimeType:@"image/jpeg" fileName:@"attachment.jpg"];
    [self presentModalViewController:mailComposer animated:YES];
}
}

上面的代码效果很好。我怎么称呼这个底部。似乎编译器只是跳过了它。
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error{
if (error){
    NSString *errorTitle = @"Mail Error";
    NSString *errorDescription = [error localizedDescription];
    UIAlertView *errorView = [[UIAlertView alloc]initWithTitle:errorTitle message:errorDescription delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
    [errorView show];
    [errorView release];
}
[controller dismissModalViewControllerAnimated:YES];

}

提前致谢。

最佳答案

尝试

mailComposer.mailComposeDelegate = self;

代替
mailComposer.delegate = self;

MFMailComposeViewController documentation:
@property(nonatomic,assign) id<MFMailComposeViewControllerDelegate> mailComposeDelegate;

关于objective-c - iOS Mail Composer不会关闭,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11434849/

10-09 15:34