如何使用UIActivityViewController发送PDF文件 [英] How to send a PDF file using UIActivityViewController

查看:1050
本文介绍了如何使用UIActivityViewController发送PDF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 UIActivityViewController 发送PDF。到目前为止,使用相当基本的方法一切正常,但我遇到的一个问题是,当我选择通过邮件发送选项时,PDF的文件名是 Attachment-1 而不是 Calculation.PDF 这是我给该文件的名称。

I'm trying to send a PDF using a UIActivityViewController. So far everything works fine using a fairly basic approach but the one issue I have is that when I select the send by mail option, the PDF's file name is Attachment-1 rather than Calculation.PDF which is the name that I give the file.

我不太关心标题的变化,但是当将文件发送给使用Windows PC的人时,缺少.pdf扩展名确实会导致问题我想解决这个问题。

I don't mind too much the change in title, but the lack of a .pdf extension does seem to cause a problem when sending the file to people with Windows PC's and I'd like to fix that.

我看过:
使用UIActivityViewController发送UIImage的控制文件名

但是看不到等效的方法:

But can't see an equivalent method to:

[mailComposer addAttachmentData: UIImagePNGRepresentation(viewImage) mimeType:@"" fileName:@"myImage.png"];

可用于PDF文件。这是没有自定义无法修复的东西,还是这个问题有一个简单的解决方案?

that will work with a PDF file. Is this something that is not fixable without customization or is there a simple solution to this problem?

推荐答案

试试这个

NSData *pdfData = [NSData dataWithContentsOfFile:pdfFilePath];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[@"Test", pdfData] applicationActivities:nil];

[self presentViewController:activityViewController animated:YES completion:nil];

以及

NSString *str = [[NSBundle mainBundle] pathForResource:@"AppDistributionGuide" ofType:@"pdf"];   
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[@"Test", [NSURL fileURLWithPath:str]] applicationActivities:nil]; 

这篇关于如何使用UIActivityViewController发送PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆