我在将屏幕截图从 ipad 转换为 pdf 并将其附加到电子邮件中时遇到了一些问题。我不明白问题出在哪里。
有人可以帮助我吗?非常感谢您的帮助。
我的调试区域:
2013-10-14 12:28:20.056 emailallegato[1309:60b] documentDirectoryFileName: /var/mobile/Applications/F4BCEBFD-3684-45A4-8D78-D88ECA5E44F4/Documents/Test.pdf
这是我的代码:
-(void)createPDFfromUIView:(UIView*)aView saveToDocumentsWithFileName:(NSString*)aFilename
{
NSMutableData *pdfData = [NSMutableData data];
UIGraphicsBeginPDFContextToData(pdfData, aView.bounds, nil);
UIGraphicsBeginPDFPage();
CGContextRef pdfContext = UIGraphicsGetCurrentContext();
[aView.layer renderInContext:pdfContext];
UIGraphicsEndPDFContext();
NSArray* documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
NSString* documentDirectory = [documentDirectories objectAtIndex:0];
NSString* documentDirectoryFilename = [documentDirectory stringByAppendingPathComponent:aFilename];
[pdfData writeToFile:documentDirectoryFilename atomically:YES];
NSLog(@"documentDirectoryFileName: %@",documentDirectoryFilename);
}
- (IBAction)iniva:(id)sender
{
[self createPDFfromUIView:self.view saveToDocumentsWithFileName:@"Test.pdf"];
NSString *path = [[NSBundle mainBundle] pathForResource:@"Test" ofType:@"pdf"];
NSData *myData = [NSData dataWithContentsOfFile:path];
MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
mail.mailComposeDelegate = self;
if([MFMailComposeViewController canSendMail]){
[mail setToRecipients:[NSArray arrayWithObjects:@"pdftest@gmail.com", nil]];
[mail setSubject:@"Oggetto "];
[mail setMessageBody:@"Messaggio e-mail" isHTML:NO];
[mail addAttachmentData:myData mimeType:@"application/pdf" fileName:@"Material Details.pdf"];
[self presentViewController:mail animated:YES completion:NULL];
}}