gpt4 book ai didi

swift - UIDocumentPickerViewController 用户选择了哪个云服务?

转载 作者:搜寻专家 更新时间:2023-10-31 22:18:08 26 4
gpt4 key购买 nike

我想从 Google Drive 和 One Drive 云服务中选择文件,为此我正在使用 UIDocumentPickerViewController

enter image description here

例如:

func didPressOneDriveChoose() {
let importMenu = UIDocumentPickerViewController(documentTypes: [(kUTTypePDF as String), (kUTTypeJPEG as String), (kUTTypePNG as String)], in: .import)
importMenu.delegate = self
importMenu.modalPresentationStyle = .formSheet
self.show(importMenu, sender: nil)
}

收到委托(delegate)方法的回调:

func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]){

var arrFiles = [Dictionary<String, AnyObject>]()
for url in urls {
// returns local document directory URL
// needs original GoogleDrive or OneDrive URL
}
}

但我想知道有什么方法可以让用户选择哪个云服务,而且我还想要指向该 URL 的原始 URL?目前,它在点击下载该文件后返回本地文档目录 URL。

最佳答案

你这样初始化:

let importMenu = UIDocumentPickerViewController(documentTypes: [(kUTTypePDF as String), (kUTTypeJPEG as String), (kUTTypePNG as String)], in: .import)

如果你read the documentation在这个特定的选择器模式 .import 上它声明:

The URLs refer to a copy of the selected documents. These documents are temporary files. They remain available only until your application terminates. To keep a permanent copy, move these files to a permanent location inside your sandbox.

.open 似乎更适合您的用例。

The URLs refer to the selected documents. The provided URLs are security-scoped, referring to files outside your app’s sandbox. For more about working with external, security-scoped URLs, see Requirements.

但是由于您只是观察 url 来识别服务,而不是实际尝试手动访问这些文档,因此您不必担心会违反任何要求。因此,将 UIDocumentPickerViewController 初始化更改为:

let importMenu = UIDocumentPickerViewController(documentTypes: [(kUTTypePDF as String), (kUTTypeJPEG as String), (kUTTypePNG as String)], in: .open)

它应该可以工作!

关于swift - UIDocumentPickerViewController 用户选择了哪个云服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49646083/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com