我正在尝试从 url 保存 pdf,然后通过电子邮件发送。发送者似乎有它,但接收者没有得到它。
当我做一个我得到NSLog
的NSString file
/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:@"123@abc.com", 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];
}