2014-01-22 31 views
1

我有一个应用程序。在点击按钮时,我想要捕获应用程序的屏幕,并打开MailComposer窗口,并且之前捕获的图像应该连接到它。发送的邮件,但没有附加的图像文件我如何将图像文件附加到iOS中的应用邮件中

PLZ帮助我。 预先感谢......,

我的代码是在这里....

MFMailComposeViewController *controller =[[MFMailComposeViewController alloc] init]; 
controller.mailComposeDelegate = self; 
[controller setSubject:@"Screen shot maker"]; 
[controller setMessageBody:@"Hi , <br/> This is Screen Shot Maker" isHTML:YES]; 
[controller addAttachmentData:[NSData dataWithContentsOfFile:@"myScreenShot.png"] mimeType:@"png" fileName:@"myScreenShot.png"]; 

if (controller) 
    [self presentModalViewController:controller animated:YES]; 

回答

0

使用下面的代码:

UIGraphicsBeginImageContext(self.view.bounds.size); 
// [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 
NSData * data = UIImagePNGRepresentation(image); 

MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init]; 
controller.mailComposeDelegate = self; 
[controller addAttachmentData:data mimeType:@"application/image" fileName:@"Test.png"]; 

if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad) 
{ 
    controller.modalPresentationStyle = UIModalPresentationFormSheet; 
} 
else 
{ 
    controller.modalPresentationStyle = UIModalPresentationFullScreen; 
} 
[self presentModalViewController:controller animated:YES]; 
+0

太感谢你了,先生......,它为我工作。 .. !!!你节省了我的时间,再次感谢你。 – user3156787

+0

雅接受先生.., – user3156787

+0

@ user3156787你没有接受我的答案。你也可以投票吗? –

相关问题