Search code examples
iosswiftnsfilemanager

How to access files out of app directory


I am developing an application which can list the phone files, such as a .pdf. But so far I could only read the files within the application directory.

The following code:

    let pathURL = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0]
    let path = pathURL.URLByAppendingPathComponent("file.pdf")
    let pathStr = path.path
    return pathStr

The above code works, but only for directories within the application directory and I need to read all directories and grab all the .pdf files. How to get access to all phone directories? For example, read and catch all the .pdf files you have on your phone. If not, please indicate the link where the restriction list.


Solution

  • Due to Apple's sandboxing, you can only read documents in your own app's directory.

    From the documentation:

    An iOS app’s interactions with the file system are limited mostly to the directories inside the app’s sandbox.