Cannot preview .xlsx file using UIDocumentInteractionController in swift 4

486 Views Asked by At

I have an application which will download .xlsx, .pdf files from a given url. When downloaded will show a local notification. Upon clicking the notification , preview of the downloaded file should be shown. I can download and preview a pdf file, but when it comes to .xlsx file, I can't preview it. I used UIDocumentInteractionController and UIDocumentInteractionControllerDelegate to interact with the file's path to preview it.

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!
}

This showFileWithPath(path: String) method will be called in UserNotification delegate method and the path of the file is passed as the parameter. This code is working fine for pdf files. But when it comes to .xlsx files, the preview is not showing any contents, just showing loading. The same case when tried with QuickLook Framework.

0

There are 0 best solutions below