MFMailComposeViewController 附件选择
我在 iPhone 应用程序中使用 MFMailComposeViewController
,我想让用户选择将一些图片附加到电子邮件中。
由于默认情况下没有特定的按钮,因此我正在考虑子类化 MFMailComposeViewController 并为此添加一个按钮。不幸的是,根据文档,一旦显示视图,就不应调用 addAttachmentData:
方法,因此在邮件撰写过程中无法做出选择。
我也考虑过创建自己的邮件编辑器视图,但根据这个问题: Send mail without MFMailComposeViewController ,Apple 不希望开发人员这样做,因为这可能会被用来滥用用户的邮件帐户。
因此,似乎唯一的解决方案是在显示 MFMailCompose 之前询问用户,而用户更改其选择的唯一方法是取消邮件撰写并重新启动,对吗?
I'm using a MFMailComposeViewController
in my iphone app and I'd like to give the user the choice to attach some pictures to the e-mail.
As there is no specific button by default, I was thinking about subclassing MFMailComposeViewController
and adding a button for this. Unfortunately, according to the documentation the addAttachmentData:
method shouldn't be called once the view has been displayed, so the choice can not be made during the mail composition.
I also thought about creating my own mail composer view, but according to this question: Send mail without MFMailComposeViewController , Apple does not want developers to do this as this could be used to abuse the user's mail account.
So, it seems the only solution is to ask the user prior to showing up MFMailCompose, and the only way for the user to change his choice would be to cancel mail composition and start it again, am I right?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当用户点击附加按钮时,关闭 MFMailComposeViewController 并打开图像拾取控制器。选取图像后,使用先前的内容和新图像作为附件创建一个新的 MFMailComposeViewController。
我还没有尝试过此操作。你可以尝试一下。
When user tap the attach button, dismiss the MFMailComposeViewController and open the image picking controller. When the image is picked, create a new MFMailComposeViewController with the previous content and the new image as attachment.
I have not tried this. You can give a try.
自我回答:对我来说,最简单的方法是在显示邮件编辑器视图之前添加一个 UIAlertView 询问用户是否要添加图像。
这已经足够了,因为所有图像都应该一起发送(所以要么全部发送,要么全不发送),但对于更复杂的情况(例如,从 iPhone 中选择一些图像),Anil Sivadas 的答案可能是一个解决方案。
Self answer: for me, the simplest way was to add a UIAlertView asking the user wether he wants to add the images or not, prior to showing up the mail composer view.
This is adequate as all images should be sent together (so it's all or none), but for more elaborate cases (chose some images from the iphone for example), Anil Sivadas' answer might be a solution.