ios - 我们如何在ios中查看和分享下载的文件

标签 ios iphone file pdf file-manager

在我的项目中,我从 NSData 保存了 PDF 文件并在 WebView 中显示,它工作正常,我检查了模拟器并在应用程序文件夹中找到文件已成功下载,没有任何损坏。

这里我的问题是如何在真实设备(iPhone 和 iPad)中查看文件并共享文件。像安卓文件管理器..

没有查看和共享(邮件、Whatsapp 等)文件的选项吗?

下面是我的代码

 NSError *errr;
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
    NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"/Folder"];
    if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath])
    {
        [[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&errr]; //Create folder

        [data writeToFile:[NSString stringWithFormat:@"%@/%@", dataPath, @"Report.pdf"] atomically:YES];
    }
 [self.webView loadData:data MIMEType:@"application/pdf" textEncodingName:@"utf-8" baseURL:nil];

帮帮我..

最佳答案

Actually, instead of WebView you could also use the QuickLook Framework, which is designed for this specific purpose. You just pass the location of the file and conform to the protocols. It will present a view controller with the document inside and also give you native options to share and open the document in other apps.

寻找答案here .

关于ios - 我们如何在ios中查看和分享下载的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48020577/

相关文章:

ios - 当图像改变大小时 MTKView 显示 CIImage 出错

iOS 7通用后台UIViewController

c - 如果文件未以 sudo 打开,则系统调用 open C 无法打印文件内容

iphone - 在 objective-c 中只从磁盘读取文件的一部分

bash - grep 重定向不匹配

ios - 如何在 ios 中生成包含图像数组的单页 pdf 文件?

ios - 是否可以无线调试 iphone webapp?

ios - UIToolBar 更改标签后恢复

ios - 处理 iOS 7 native 登录弹出窗口中“取消”的选择

iphone - 在 Obj C 中使用 Brad Larson GPUImage 为照片创建素描效果