iosswiftxcodeqlpreviewcontroller

QLPreviewController is showing the document name instead of file content for the files coming from server


Using QLPreviewController for previewing documents like pdf , doc , xlsx but is is not showing the file content.The file to display is being fetched from server.I just want to show the pdf through the url link coming from server like an image is previewed.

Do we need to save the file first to app's document directory?

Can someone please help?


Solution

  • QLPreviewController isn't really designed to download files.

    @property(readonly, nonatomic) NSURL *previewItemURL;
    

    This property is used by a Quick Look preview controller to get an item’s >URL. In typical use, you would implement a getter method in your preview >item class to provide this value.

    The value of this property must be a file-type URL.

    You can download the file via URLSession with downloadTask

    https://developer.apple.com/reference/foundation/urlsession/1411511-downloadtask

    After download you can move the file in document directory and then view it.