在我的应用程序中,我必须生成PDF并使用mfmail compose controller发送该附件。要生成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附加为编辑器附件的代码:
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"]];
答案 0 :(得分:0)
答案 1 :(得分:0)
尝试将mimeType:@"application/pdf"
更改为mimeType:@"text/pdf"
,当我遇到同样的问题时,它对我有用。