OGeek|极客世界-中国程序员成长平台

标题: iphone - 在 iOS 中使用电子邮件 uri 方案的附件 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 10:39
标题: iphone - 在 iOS 中使用电子邮件 uri 方案的附件

我正在实现一个 iphone 应用程序 (iOS 4.2),我想从该应用程序触发电子邮件客户端发送带有附件的消息。我可以有效地结合使用 uri 方案和类 NSURL 来触发电子邮件应用程序,但我想知道是否可以附加图像。我曾尝试使用 mailto:[email protected]?subject=sthg&body=sthgelse&attachment=/path/to/file 但附件不包括在内。我知道 iphone 应用程序是沙盒的,因此电子邮件实用程序可能无法访问我的图像的路径,因为它位于我的应用程序包中。另一方面,我正在考虑使用照片管理器管理我的图像。 (1)有没有办法以这种方式包含附件? (2) 如果是这样,是否可以从我的应用程序或照片客户端引用图像?我在 mailto RFC 中找不到任何附件参数,但也许 Apple 提供了一些方法来实现这一点。

提前感谢您的帮助,

路易斯



Best Answer-推荐答案


MFMailComposeViewController 将能够做到这一点,下面的一些使用示例: 记得添加 MessageUI.framework

MFMailComposeViewController *email = [[MFMailComposeViewController alloc] init];
email.mailComposeDelegate = self;
[email setSubject"Whatever"];

// Set up recipients
NSArray recipients = [NSArray arrayWithObject"[email protected]"]; 

[email setToRecipients:recipients];


// Attach an image to the email
UIImage *attachment = ...;
NSData *data = UIImagePNGRepresentation(attachment);
[email addAttachmentData:myData mimeType"image/png" fileName"ok.png"];

// Fill out the email body text
NSString *emailBody = @"test mail";
[email setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];

[email release];

关于iphone - 在 iOS 中使用电子邮件 uri 方案的附件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8833916/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4