【发布时间】:2026-01-19 15:10:01
【问题描述】:
我已经编写了这段代码来使用 UIDocumentInteractionController 显示 pdf。但是,我不知道如何在本地目录中搜索 pdf 并在 iOS 8 及以下版本中打开..有什么帮助吗?
let filename = history.invoiceLongDate // 01223642
if !filename.isEmpty{
let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
let docs = paths[0]
let pathURL = NSURL(fileURLWithPath: docs, isDirectory: true)
if #available(iOS 9.0, *) {
let fileURL = NSURL(fileURLWithPath: "\(filename)_my_invoice.pdf", isDirectory: false, relativeToURL: pathURL)
self.docController = UIDocumentInteractionController(URL: fileURL)
self.docController?.delegate = self
self.docController?.presentOptionsMenuFromRect(sender.frame, inView: self.view, animated: true)
} else {
// Fallback on earlier versions
// Any Help with that?
}
}
【问题讨论】:
标签: swift ios8 nsfilemanager uidocumentinteraction