我有一个应用程序,它将从给定的 url下载.xlsx、.pdf文件。下载后会显示本地通知。单击通知后,应显示下载文件的预览。我可以下载和预览 pdf 文件,但是对于 .xlsx 文件,我无法预览。我使用UIDocumentInteractionController
并UIDocumentInteractionControllerDelegate
与文件的路径交互来预览它。
func showFileWithPath(path: String)
{
print(path)
let isFileFound:Bool? = FileManager.default.fileExists(atPath: path)
if isFileFound == true
{
let viewer = UIDocumentInteractionController(url: URL(fileURLWithPath: path))
viewer.delegate = self
viewer.presentPreview(animated: true)
}
}
func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController
{
return self.navigationController!
}
该showFileWithPath(path: String)
方法将在UserNotification
委托方法中调用,并将文件的路径作为参数传递。此代码适用于 pdf 文件。但是当涉及到 .xlsx 文件时,预览没有显示任何内容,只是显示正在加载。尝试使用QuickLook Framework
.