我想使用swift 4打开文档文件。我的要求是我要使用文档选择器。使用文档选择器,我可以使用我的应用程序上传该文件。 简而言之,在我的应用程序中,我希望从设备获取其他文档(例如.pdf)。我试过了。
func documentMenu(_ documentMenu: UIDocumentMenuViewController, didPickDocumentPicker documentPicker: UIDocumentPickerViewController) {
documentPicker.delegate = self
present(documentPicker, animated: true, completion: nil)
}
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
let myURL = urls
print("import result : \(myURL)")
}
func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {
print("view was cancelled")
dismiss(animated: true, completion: nil)
}
@IBAction func dsds(_ sender: Any) {
let importMenu = UIDocumentMenuViewController(documentTypes: [String(kUTTypePDF)], in: .import)
importMenu.delegate = self
importMenu.modalPresentationStyle = .formSheet
self.present(importMenu, animated: true, completion: nil)
}