iOS - How to access the device's file library?

2019-07-19 17:08发布

问题:

I'm trying to build an app that can open any pdf stored on the device and I really have no idea on how to get a handle to these files. I've searched the documentation and every single class that I found assumes that I already have a handle to the file.

There must be something that I am missing here. There are several apps that can access audio and pictures files. Surely there must be a way to access pdf files right?

回答1:

Apple doesn't really give you access to "any pdf stored on the device". You need to either get the file through iTunes sharing, an external server, or get passed the file via a custom URL scheme.



回答2:

Nope. There is no device-wide document store, and you cannot access files stored inside another app's app bundle, so you cannot access saved PDFs. There is no shared place for the user to save such PDFs in the first place. The media libraries have specific APIs to access them because they are device-wide libraries.

The most you can do is register your app as a viewer of PDF documents. This would allow other apps to open a PDF in your app if they use a UIDocumentInteractionController.