2012-01-12 65 views
2

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

预先感谢您的帮助,

路易斯

回答

3

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]; 
0

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

+0

谢谢..它似乎是正确的做法。毕竟mailto方案不考虑任何参数来表示附件.. – 2012-01-16 10:15:48

0

如果一个人没有考虑MFMailComposeViewController简单地崩溃。 是的,你可以先致电canSendMail,结果NO(!),接下来是什么? 答案是 - 使用'mailto:'。它会弹出对话框来创建帐户。