我有点麻烦,我花了半天时间来解决这个问题,在 iOS6 和其他问题的所有弃用之后,我没有取得重大成果。这个 iOS 应用程序有一个发送电子邮件选项,当按下按钮后,该应用程序会截取我的 WebView 的屏幕截图,将其附加到电子邮件中,然后从那里,具有取消或发送电子邮件并返回应用程序的正常选项。我到达了弹出电子邮件的部分,实际上这里有两个问题:一个是按下取消或发送后,电子邮件视图不会关闭,应用程序卡在电子邮件视图中。我遇到的第二个问题是附加的图像只是一个小图标(带有问号的蓝色,就像它未被识别或丢失一样......有人可以指出我正确的方向吗?我要疯了。我 我在没有运气的情况下前后研究了网络。不幸的是,许多类似的线程但不同的问题与我的问题并不完全相关。对不起,提前谢谢。这是我的代码:
// in my LiveView.h file
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#import <MessageUI/MessageUI.h>
#import "CamSetup.h"
@interface LiveView : UIViewController < MFMailComposeViewControllerDelegate , ADBannerViewDelegate >
....
-(IBAction)shotAndSend:(id)sender;
// in my LiveView.m file:
- (void)mailComposer:(MFMailComposeViewController *)controller
didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
NSLog(@"in didFinishWithResult:");
switch (result)
{
case MFMailComposeResultCancelled:
NSLog(@"cancelled");
break;
case MFMailComposeResultSaved:
NSLog(@"saved");
break;
case MFMailComposeResultSent:
NSLog(@"sent");
break;
case MFMailComposeResultFailed: {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Error sending mail",@"Error sending mail")
message:[error localizedDescription] delegate:nil
cancelButtonTitle:NSLocalizedString(@"test",@"test")
otherButtonTitles:nil];
[alert show];
break;
}
default: break;
}
[self dismissViewControllerAnimated:NO completion:Nil];
}
-(IBAction)shotAndSend:(id)sender
{
UIGraphicsBeginImageContext(_myWebView.frame.size);
[_myWebView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData * imageData = UIImageJPEGRepresentation (image, 2.1);
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController * mailComposer = [[MFMailComposeViewController alloc] init];
mailComposer.mailComposeDelegate = self;
[mailComposer addAttachmentData:imageData mimeType:@"image/jpeg" fileName:@"attachment.jpeg"];
[mailComposer setSubject:@"A screenshot from my App"];
[mailComposer setToRecipients:[NSArray arrayWithObjects:@"123@yexample.com", nil]];
[self presentViewController: mailComposer animated:YES completion:NULL];
}
}