在我的项目中,我从 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/