12

我的应用程序现在Documents在 iOS 11 文件应用程序“在我的 iPhone”部分上共享目录。

(感谢这篇文章:Working with the Files App in iOS 11

问题是如何通过 URL Scheme 打开此目录或至少 File 应用程序根页面。UIDocumentPickerViewController或者UIDocumentBrowserViewController在这种情况下没有帮助。

4

3 回答 3

3
    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
        )
    }
于 2021-03-15T14:29:15.313 回答
2

文件应用程序可以使用 URL 方案打开shareddocuments://

但是,我不知道是否有办法打开特定目录。

于 2019-03-06T13:08:30.407 回答
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)
    }

这段代码可以工作。

于 2020-04-08T07:45:38.370 回答