Open iOS 11 Files app via URL Scheme or some other way

7.4k Views Asked by At

My app is now sharing Documents directory on iOS 11 Files app "On My iPhone" section.

(Thanks to this article: Working with the Files App in iOS 11)

Question is how to open this directory or at least File app root page via URL Scheme. UIDocumentPickerViewController or UIDocumentBrowserViewController doesn't help in this situation.

3

There are 3 best solutions below

0
On
    func openSharedFilesApp() {
        let documentsUrl =  FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
        let sharedurl = documentsUrl.absoluteString.replacingOccurrences(of: "file://", with: "shareddocuments://")
        print(sharedurl)
        let furl:URL = URL(string: sharedurl)!
        UIApplication.shared.open(furl, options: [:], completionHandler: nil)
    }

This code would work.

3
On
    guard let documentDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first,
          let components = NSURLComponents(url: documentDirectory, resolvingAgainstBaseURL: true) else {
        return
    }
    components.scheme = "shareddocuments"
    
    if let sharedDocuments = components.url {
        UIApplication.shared.open(
            sharedDocuments,
            options: [:],
            completionHandler: nil
        )
    }
0
On

The Files app can be opened with the URL scheme shareddocuments://.

I don’t know if there’s a way to open a specific directory however.