我需要能够在我的应用程序中发送一封电子邮件,其中附有 iPhone 当前显示的屏幕截图。您单击一个按钮,我将带您进入附有屏幕截图的电子邮件,并且没有将图片保存到相机中。您按下的按钮应该在操作表中。我知道发送电子邮件和操作表的代码,但我需要知道如何使邮件按钮位于操作表中,包括屏幕截图。
问问题
185 次
1 回答
1
UIActionSheet *options = [[UIActionSheet alloc] initWithTitle:@"Options" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Email", nil];
[options showInView:self.view];
#pragma mark ActionSheet Delegate
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
switch (buttonIndex)
{
case 0:
{
}
default:
break;
}
}
#pragma mark Email
//Allocating Memory for MailComposer
MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
mailController.mailComposeDelegate = self;
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *exportData = UIImageJPEGRepresentation(image ,1.0);
[mailController addAttachmentData:exportData mimeType:@"image/jpeg" fileName:@"Screenshot.jpeg"];
[self presentModalViewController:mailController animated:YES];
编辑:
#pragma mark MailComposer Delegate
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
[self dismissModalViewControllerAnimated:YES];
}
记得在头文件中添加 MFMailComposeViewControllerDelegate。
希望这对您有所帮助。
于 2013-07-03T14:53:55.730 回答