I am using this simple tool for previewing different files in my app, but none of them is being successfully previewed.
First time I try to preview any file it opens preview controller with message Unsupported file format
, and any other time it just displays filename and word data
(see images).
Here is the implementation(Pay attention on the print statements):
extension FileShareVC: QLPreviewControllerDataSource, QLPreviewControllerDelegate {
func numberOfPreviewItems(in controller: QLPreviewController) -> Int {
filesList.count
}
func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem {
let url = NSURL(fileURLWithPath: filesList[index].filePath ?? "", isDirectory: false)
print(filesList[index].filePath!)
//prints file:///var/mobile/Containers/Data/Application/AB608864-C682-47BB-8396-2D456430879E/Documents/F9RIB62HBUAW.jpeg
print("url: \(url)")
//prints file:/var/mobile/Containers/Data/Application/AB608864-C682-47BB-8396-2D456430879E/Documents/F9RIB62HBUAW.jpeg -- file:///
return url
}
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
let quickLookViewController = QLPreviewController()
quickLookViewController.dataSource = self
quickLookViewController.delegate = self
quickLookViewController.currentPreviewItemIndex = indexPath.row
present(quickLookViewController, animated: true)
}
I am not sure why my url appends -- file:///
on the file path, maybe that causes the problem?