SwiftUI : QuickLook doesn't not work correctly in iPad device

Viewed 249

I tried to using QuickLook framework.

For editting PDF, I implemented "previewController(_: editingModeFor: )" in Coordinator.

In Xcode(ver 11.6) simulator, quicklook view has pencil markup tool. In Xcode simulator

But in my iPad(PadOS 13.6), there is no markup tool. In my iPad device, PadOS 13.6

Is there any bugs in QuickLook framework?

Here is my code.

PreviewController.swift

import SwiftUI
import QuickLook
struct PreviewController: UIViewControllerRepresentable {
    let url: URL
    @Binding var isPresented: Bool
    func makeUIViewController(context: Context) -> UINavigationController {
        let controller = QLPreviewController()
        controller.dataSource = context.coordinator
        controller.delegate = context.coordinator
        let navigationController = UINavigationController(rootViewController: controller)
        return navigationController
    }
    func updateUIViewController(_ uiViewController: UINavigationController, context: Context) {}
    func makeCoordinator() -> Coordinator {
        return Coordinator(parent: self)
    }
    class Coordinator: NSObject, QLPreviewControllerDelegate, 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
    }
    /* 
Return .updateContents so QLPreviewController takes care of updating the contents of the provided QLPreviewItems whenever users save changes.
*/    
    func previewController(_ controller: QLPreviewController, editingModeFor previewItem: QLPreviewItem) -> QLPreviewItemEditingMode {
    return .updateContents
        }
    }
}

ContentView.swift

import SwiftUI
struct ContentView: View {
    let fileUrl = Bundle.main.url(forResource: "LoremIpsum", withExtension: "pdf")!
    @State private var showingPreview = false
    var body: some View {
        Button("Preview File") {
            self.showingPreview = true
        }
        .sheet(isPresented: $showingPreview) {
            PreviewController(url: self.fileUrl, isPresented: self.$showingPreview)
        }
    }
}
0 Answers
Related