0
votes

I am trying to open a file using the QuickLook framework. All the resources I am finding online show how to open a file stored locally with quicklook, however, is it possible to open a file using a url link (which is not stored locally)?

In my attempts, I have failed. Here is what I've done:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    let file = fetchedResultsController.object(at: indexPath)

    var fileToPreviewURL = "https://s3-us-west-1.amazonaws.com/powr/defaults/image-slider1.jpg"

    let urlToCheck = NSURL(string: fileToPreviewURL)

    if QLPreviewController.canPreview(urlToCheck) {
        print("Can preview!")
        quickLookController.currentPreviewItemIndex = 0
        navigationController?.pushViewController(quickLookController, animated: true)
    }else{
        print("Cannot preview") //printing out this in console when run app
    }

}

And my delegate methods:

extension TaskViewVC:  QLPreviewControllerDataSource {

    func numberOfPreviewItems(in controller: QLPreviewController) -> Int {
        return 1
    }

    func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem {

        let url = NSURL(string: "https://s3-us-west-1.amazonaws.com/powr/defaults/image-slider1.jpg")

        return url!
    }
}

I'm not sure why it QLPreviewController cannot preview the urlToCheck, which is a completely valid URL with an image.

1

1 Answers

0
votes

As far as I know, previewing from a URL is not supported. You should probably file a bug on bugreport.apple.com?