Open iOS 11 Files app via URL Scheme or some other

2020-08-26 03:31发布

问题:

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.

回答1:

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.



回答2:

    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.