如何将 pdf 保存到我的应用程序资源文件夹中,并在运行时访问它们?
我正在设计一个应用程序,可以查看大量 PDF。有很多不同的语言可用,所以如果我将所有这些语言都包含在应用程序中,那么大小将达到 100+ mb,根本无法运行。
所以我想我要把pdf放在我的服务器上,并通过直接下载链接访问它们,如下所示:
http://mysite.com/pdfs/thepdf.pdf
这将返回我想要的确切pdf。所以我想知道如何在即时下载这些资源时访问它们?
我想我需要将 pdf 保存到应用程序资源文件夹中?然后,当选择 pdf 的 tableView 行时,我检查 pdf 是否位于资源文件夹中(我该怎么做?),如果没有,则将其从服务器上拉下来,然后将其加载到我的视图中?
我想我对我需要做什么有一个很好的想法,只是不太清楚执行它的代码。任何人都可以发布用于访问资源文件夹的代码(如果这实际上是我需要做的),以及如何检查资源文件夹中是否有某些内容的代码?
谢谢!
I have an app I'm designing that will allow for lots of PDF viewing. There are a lot of different languages available, and so if I were to include all of them in the app, it would be like 100+ mb in size which just won't fly.
So I'm thinking that I am going to put the pdf's on my server, and access them with a direct download link like this:
http://mysite.com/pdfs/thepdf.pdf
Which will return the exact pdf I want. So I'm wondering how I can go about accessing these resources as I download them on the fly?
I imagine I need to save the pdf's to the app resources folder? And then when a tableView row for the pdf is selected, I check if the pdf is in the resources folder (how do I do that?), and if not, pull it down off the server, and load it into my view?
I think I have an okay idea of what I need to do, just not very clear on the code to do it. Can anybody post the code for accessing the resources folder (if that's actually what I need to be doing), and maybe the code for how to check if something is in the resources folder?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否考虑过使用 UIWebView 来查看 PDF,而不是自己下载和加载它? UIWebView 应该负责缓存,所以你不必担心这一点。
假设 UIWebView 不起作用,要下载 PDF 并查看它们是否存在,您需要将其存储在 Documents 文件夹中。将应用程序提交给 Apple 后,资源文件夹将无法更改,但应用程序中的 Documents 文件夹完全没问题。要访问它,我实际上会推荐 ConciseKit,可以在 GitHub 上找到。它为您提供了访问应用程序文档目录的辅助方法。辅助方法是
然后你可以通过以下方式获取文件的路径
这就是获取文件路径的方法,要检查它是否存在,你需要使用 NSFileManager。
Have you considered using a UIWebView to view the PDF instead of downloading and loading it yourself? UIWebView should take care of caching, so you won't have to worry about that.
Assuming that a UIWebView won't work, to download PDFs and see if they exist, you need to store it in the Documents folder. The resources folder cannot be altered after you submit your app to Apple, but the Documents folder in your app is completely fine. To access it, I would actually recommend ConciseKit, which can be found on GitHub. It gives you a helper method to access your app's document directory. The helper method is
Then you can get the path for a file by doing
So that is how you get a path to a file, to check if it exists, you want to use NSFileManager.