我想從一個URL保存PDF然後通過電子郵件發送。發件人似乎有它,但接收方不明白。保存PDF然後通過電子郵件發送
當我做NSString file
的NSLog
我得到/var/mobile/Applications/0ADE222E-6346-4C6C-8348-DA5327B980AA/Documents/myPDF.pdf
這似乎是它可以節省,但它不會發送。這是我下面的保存和發送
編輯
更新代碼
// This pdfURL is 0 bytes
NSData *pdfURL = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",webPage.urlString]]];
//Store the Data locally as PDF File
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [paths objectAtIndex:0];
NSString *file = [documentDirectory stringByAppendingFormat:@"/myPDF.pdf"];
[pdfURL writeToFile:file atomically:YES];
//Sending the pdf
MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
composer.mailComposeDelegate = self;
if ([MFMailComposeViewController canSendMail]){
//Changed email for privacy issues
[composer setToRecipients:[NSArray arrayWithObjects:@"[email protected]", nil]];
[composer setSubject:[NSString stringWithFormat:@"%@ email",titleText]];
[composer setMessageBody:@"your custom body content" isHTML:NO];
NSLog(@"pdf %@",file);
// This pdfData is 0 bytes
NSData *pdfData = [NSData dataWithContentsOfFile:file];
[composer addAttachmentData:pdfData mimeType:@"application/pdf" fileName:@"myPDF.pdf"];
[composer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentModalViewController:composer animated:YES];
}
你試過沒有「/」在你的addAttachmentData調用的文件名部分? – trumpetlicks 2012-07-13 13:26:17
是的,我有。因爲之前我讀過的東西,我就在那裏。它不起作用,雖然 – BigT 2012-07-13 13:30:15
在你打電話給addAttachmentData之前,你能檢查你的PDF數據的大小,以確保有真正被讀取的東西嗎? – trumpetlicks 2012-07-13 13:56:19