Ios 目标C:拍照并通过电子邮件发送

Ios 目标C:拍照并通过电子邮件发送,ios,objective-c,uiimage,uiimagepickercontroller,mfmailcomposeviewcontroller,Ios,Objective C,Uiimage,Uiimagepickercontroller,Mfmailcomposeviewcontroller,我正在尝试制作一个应用程序,使用该设备的摄像头拍摄照片,然后将其连接到电子邮件。我试图编码它,但图像没有附加。我所做的是在拍摄完照片后,首先在UIImageView上查看它,然后单击“完成”按钮将图像保存到沙盒并检索它以供附件 这是我的密码: 为了保存图像 NSData *imgData = UIImageJPEGRepresentation(attachingImage, 1); jpgPath = [NSHomeDirectory() stringByAppendingPathCompone

我正在尝试制作一个应用程序,使用该设备的摄像头拍摄照片,然后将其连接到电子邮件。我试图编码它,但图像没有附加。我所做的是在拍摄完照片后,首先在
UIImageView
上查看它,然后单击“完成”按钮将图像保存到沙盒并检索它以供附件

这是我的密码: 为了保存图像

NSData *imgData = UIImageJPEGRepresentation(attachingImage, 1);
jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"defectImg.jpg"];
[imgData writeToFile:jpgPath atomically:YES];
附件

    UIImage *myImage = [UIImage imageNamed:jpgPath];
    NSData *myImageData = UIImagePNGRepresentation(myImage);
    [tempMailCompose addAttachmentData:myImageData mimeType:@"image/jpeg" fileName:@"defectImage.jpg"];

可能有什么问题?

[UIImage imageNamed:][/code>不会加载任意图像。它可以从您的包中加载图像(您在Xcode中添加的图像),仅此而已

而不是
UIImage*myImage=[UIImage-imagename:jpgPath]

您想使用
imageWithContentsOfFile:
从磁盘加载图像

UIImage *myImage = [UIImage imageWithContentsOfFile:jpgPath];
此外:

您正在创建png图像并将其作为jpeg附加


无需将NSData保存到磁盘,只需在几秒钟后加载即可。将imgData引用传递给邮件生成器。

。你可以用html写一封信。所以你决定把照片放在哪里

MFMailComposeViewController *mailController = [MFMailComposeViewController new];
mailController.mailComposeDelegate = self;
NSString *subject = [NSString stringWithFormat:@"%@ by %@", m_art.title, [m_art.author authorFullNameByReverse:NO]];
[mailController setSubject:subject];

NSString *body = [NSString stringWithFormat:@"<html><body>Hi,<br>"];
body = [body stringByAppendingFormat:@"<img src='%@' width = '50%%' height = '50%%'><br>", [Utils urlAtArtPath:m_art.url]];
body = [body stringByAppendingFormat:@"More info here: <a href='%@'>%@</a></body></html>", m_art.url, m_art.url];

m_mail.enabled = NO;

[mailController setMessageBody:body isHTML:YES];
MFMailComposeViewController*mailController=[MFMailComposeViewController new];
mailController.mailComposeDelegate=self;
NSString*主题=[NSString stringWithFormat:@“%@by%@”,m_art.title,[m_art.author author fullnamebreverse:NO]];
[邮件控制器设置主题:主题];
NSString*body=[NSString stringWithFormat:@“嗨,
”]; body=[body stringByAppendingFormat:@“
”,[Utils urlAtArtPath:m_art.url]]; body=[body stringByAppendingFormat:@“此处有更多信息:”,m_art.url,m_art.url]; m_mail.enabled=否; [mailController setMessageBody:body isHTML:YES];
什么是UTIL和m_邮件?谢谢!我确实把这个意象传给了《邮件作曲家》。它正在工作。