当我从我的应用程序通过电子邮件发送屏幕截图时,我无法在调用电子邮件客户端时关闭它。即使我点击了取消,也不会发生任何事情,有人能告诉我我做错了什么吗。
- (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];
您需要将委托设置为mailComposer.mailComposeDelegate = self;
然后调用邮件编写器委托方法中的disse方法:
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
// Do any processing before dismissing
[self dismissModalViewControllerAnimated:YES];
}