TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

Quick look preview only shows a blurred 1st page of documents in MacOS

Forums > 100 Days of SwiftUI

I have a SwiftUI iOS app that I have made available for mac catalyst. I am using QuickLook Preview to dispaly pdf, docx, images and pptx in the app. The rendering works fine on iOS but on MacOS, only 1 page of the document is displayed with a blurry look.

Here is my code that implements the QuickLook:

import SwiftUI
import QuickLook

struct PreviewController: UIViewControllerRepresentable {

    @Binding var url: URL

    func makeUIViewController(context: Context) -> QLPreviewController {
        let controller = QLPreviewController()
        controller.dataSource = context.coordinator
        return controller
    }

    func updateUIViewController(
        _ uiViewController: QLPreviewController, context: Context) {}

    func makeCoordinator() -> Coordinator {
        return Coordinator(parent: self)
    }

    class Coordinator: QLPreviewControllerDataSource {

        let parent: PreviewController

        init(parent: PreviewController) {
            self.parent = parent
        }

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

        func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem {
            return parent.url as NSURL
        }

    }
}

and then I calling it in my Content view in a sheet. Question is what do I do differently to render the documents properly on the MacOS?

2      

Hacking with Swift is sponsored by Blaze.

SPONSORED Still waiting on your CI build? Speed it up ~3x with Blaze - change one line, pay less, keep your existing GitHub workflows. First 25 HWS readers to use code HACKING at checkout get 50% off the first year. Try it now for free!

Reserve your spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.