我不知道我理解你的問題,你可能是要重視一個PDF文件或者你是否只想添加一個鏈接到PDF文檔,所以我會回答這兩個問題。下面是我使用的PDF數據附加到
- (void)emailFile
{
if(![MFMailComposeViewController canSendMail]) {
UIAlertView *cantSend = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Device not configured to send email" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[cantSend show];
} else {
MFMailComposeViewController *mailView = [[MFMailComposeViewController alloc] init];
mailView.mailComposeDelegate = self;
[mailView setSubject:@"PDF Attached to email"];
// Adding an actual PDF document to the email.
[mailView addAttachmentData:(__bridge NSData *)myPDFData mimeType:@"pdf" fileName:@"AttachedPDFDocument"];
[mailView setMessageBody:[NSString stringWithFormat:@"Sending %@. This email maybe sent as junk mail",fileName] isHTML:NO];
[self presentModalViewController:mailView animated:YES];
}
}
通知我加入了PDF格式的數據,而不是實際的PDF,然後我設置分機(Mime類型)爲PDF,然後設置的名稱的郵件代碼文件,這是很簡單的附件添加到您正在構建的電子郵件。
要添加鏈接到電子郵件它很簡單,只要
- (void)emailFile
{
if(![MFMailComposeViewController canSendMail]) {
UIAlertView *cantSend = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Device not configured to send email" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[cantSend show];
} else {
MFMailComposeViewController *mailView = [[MFMailComposeViewController alloc] init];
mailView.mailComposeDelegate = self;
[mailView setSubject:@"PDF Link added in HTML"];
// Adding a HTML Link to an email. Remembering to set the Message to allow HTML.
NSString *link = [NSString stringWithFormat:@"http://www.google.com"];
[mailView setMessageBody:[NSString stringWithFormat:@"<p><font size=\"2\" face=\"Helvetica\"><a href=%@></br>%@</br></a></br></font></p>",link,@"Google"] isHTML:YES];
[self presentModalViewController:mailView animated:YES];
}
}
注意,你是不附加任何數據把你正在設置setMessage
,而第一個例子中不使用HTML使用HTML 。這將允許您在包含html元素的消息正文中設置NSString
。
編輯
myPDFData是我從web服務下載,然後用戶可以通過電子郵件轉發給自己的PDF的dataContent的CFDataRef
。如果你正在使用ARC
則需要設置attachmentData時添加的橋(__bridge NSData *)myPDFData
。
希望這會有所幫助。
粘貼的你已經嘗試 –
如果要添加一個鏈接,爲什麼不把它放到電子郵件的正文中的代碼?的 – propstm
可能重複[MFMailComposeViewController:我怎麼嵌入一個可點擊的URL鏈接到電子郵件正文](http://stackoverflow.com/questions/2058447/mfmailcomposeviewcontroller-how-do-i-embed-a-clickable-url-鏈接到最電子郵件) – petert