将图像附加到电子邮件中?

发布于 2024-09-30 09:52:24 字数 414 浏览 0 评论 0原文

我想使用 MFMailComposeViewController 发送电子邮件,并且我已经进行了设置,但我在实际将图像(屏幕截图)附加到电子邮件中时遇到了麻烦。

这是代码行。

[composer addAttachmentData:image mimeType:image/png //png undeclared//fileName:@"GameOver Screenshot.png"]; //Incompatible Obj-C types 'struct UIImage *' expected 'struct NSData *' when passing argument 1 of .....//

image 是我的 UIImage 屏幕截图的名称。我不知道用什么来代替它。

预先感谢您的帮助/帮助。

I want to to use MFMailComposeViewController to send an email, and I already have that set up, but I'm having trouble actually attaching an image, which is a screenshot, into the email.

Here's the line of code.

[composer addAttachmentData:image mimeType:image/png //png undeclared//fileName:@"GameOver Screenshot.png"]; //Incompatible Obj-C types 'struct UIImage *' expected 'struct NSData *' when passing argument 1 of .....//

image is the name of my UIImage screenshot. I'm not sure what to replace it with.

Thanks in advance for the help/assistance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苍景流年 2024-10-07 09:52:24

addAttachmentData 的第一个参数是附件的 NSData。如果您的 image 是 UIImage,请尝试以下操作:

NSData *data = UIImagePNGRepresentation(image);
[composer addAttachmentData:data 
                   mimeType:@"image/png" 
                   fileName:@"GameOver Screenshot.png"];

The first parameter to addAttachmentData is an NSData of the attachment. If your image is a UIImage, then try this:

NSData *data = UIImagePNGRepresentation(image);
[composer addAttachmentData:data 
                   mimeType:@"image/png" 
                   fileName:@"GameOver Screenshot.png"];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文