如何在我的应用程序中获取ibook的pdf文件?

时间:2018-12-11 11:03:58

标签: ios swift

我想使用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)
}

0 个答案:

没有答案