2

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

在此先感谢您的帮助,

路易斯

4

3 回答 3

3

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

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

// Set up recipients
NSArray recipients = [NSArray arrayWithObject:@"whoever@wherever.org"]; 

[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];
于 2012-01-13T01:22:51.097 回答
0

您应该使用允许添加附件的MFMailComposeViewController ,而不是使用mailto:URL 方案。它还具有额外的好处,即使用不会离开您的应用程序。

于 2012-01-12T11:06:46.230 回答
0

如果一个人没有帐户 MFMailComposeViewController 只会崩溃。是的,您可以canSendMail先调用结果为 NO(!),然后呢?答案是 - 使用'mailto:'。它会弹出对话框来创建帐户。

于 2015-01-21T17:23:11.907 回答