[英]PDF Attachment not receive in mail while sending mail via IPad
在我的應用程序中,我必須生成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"]];
與ipad視圖相比,您將uiview(pdfView)渲染為PDF高度需要更多。 如果小於ipad視圖,它將作為內聯附件附加。內聯附件對mozila不可見,因此最好在Safari中查看內聯附件。 如果您想以單個附件的形式查看,則必須增加pdf視圖的高度,而不是內聯附件。
嘗試將mimeType:@"application/pdf"
更改為mimeType:@"text/pdf"
,當我遇到相同的問題時,它對我有用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.