在我的应用程序中,我必须生成 PDF 并使用 mfmail compose 控制器发送该附件。要生成 pdf,我使用 CALayer 类将 uiview 呈现为 PDF。生成的pdf需要作为附件发送给相应的用户。现在的问题是,在接收端附件是可见的,并且只收到了从 iphone 发送的邮件,而不是从 ipad 发送的邮件。发送邮件时它显示完美,但不显示在邮件中(如果从 Ipad 发送邮件)。指导我解决这个问题。这是我生成 PDF 的代码。
NSMutableData *pdfData = [NSMutableData data];
UIGraphicsBeginPDFContextToData(pdfData, pdfView.bounds, nil);
UIGraphicsBeginPDFPage();
CGContextRef pdfContext = UIGraphicsGetCurrentContext();
[pdfView.layer renderInContext:pdfContext];
// remove PDF rendering context
UIGraphicsEndPDFContext();
// Retrieves the document directories from the iOS device
NSArray* documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
NSString* documentDirectory = [documentDirectories objectAtIndex:0];
NSString* documentDirectoryFilename = [documentDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.pdf",[receivedSelectedDict valueForKey:@"reportID"]]];
NSLog(@"while creating %@",documentDirectoryFilename);
// instructs the mutable data object to write its context to a file on disk
[pdfData writeToFile:documentDirectoryFilename atomically:YES];
将 PDF 作为 Composer 附件附加的代码:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *file = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.pdf",[receivedSelectedDict valueForKey:@"reportID"]]];
NSLog(@"while fetching %@",file);
NSMutableData *data=[NSMutableData dataWithContentsOfFile:file];
[mailViewController addAttachmentData:data mimeType:@"application/pdf" fileName:[receivedSelectedDict valueForKey:@"reportID"]];