我的应用程序现在Documents
在 iOS 11 文件应用程序“在我的 iPhone”部分上共享目录。
(感谢这篇文章:Working with the Files App in iOS 11)
问题是如何通过 URL Scheme 打开此目录或至少 File 应用程序根页面。UIDocumentPickerViewController
或者UIDocumentBrowserViewController
在这种情况下没有帮助。
我的应用程序现在Documents
在 iOS 11 文件应用程序“在我的 iPhone”部分上共享目录。
(感谢这篇文章:Working with the Files App in iOS 11)
问题是如何通过 URL Scheme 打开此目录或至少 File 应用程序根页面。UIDocumentPickerViewController
或者UIDocumentBrowserViewController
在这种情况下没有帮助。
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
)
}
文件应用程序可以使用 URL 方案打开shareddocuments://
。
但是,我不知道是否有办法打开特定目录。
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)
}
这段代码可以工作。