PDF通过iPad发送邮件时,不会收到邮件附件

时间:2013-03-05 04:39:05

标签: ios objective-c ipad calayer

在我的应用程序中,我必须生成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"]];

2 个答案:

答案 0 :(得分:0)

与ipad视图相比,以PDF高度呈现的uiview(pdfView)需要更多。 如果它小于ipad视图,它将作为内联附件附加。莫兹拉不能看到内联附件,所以你可以在safari中查看内联附件。而不是内联附件,如果要查看单个附件,则必须增加pdf视图的高度。

答案 1 :(得分:0)

尝试将mimeType:@"application/pdf"更改为mimeType:@"text/pdf",当我遇到同样的问题时,它对我有用。