12

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.

Shingo Fukuyama
  • 1,492
  • 1
  • 17
  • 19

3 Answers3

6
    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
        )
    }
David Vatlin
  • 61
  • 1
  • 2
2

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.

Paolo
  • 3,825
  • 4
  • 25
  • 41
1
    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.

z33
  • 1,193
  • 13
  • 24