2012-01-12 69 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:'。它會彈出對話框來創建帳戶。