QuickLook Preview saving errors or no saving

Hi together, I am developing a document viewer for a specific API. I download the relevant files to a custom directory and open them using a QLPreviewController in SwiftUI. I built this with a UIViewControllerRepresentable.

Everything is working fine except the saving of modified files using the pencil markup in the preview.

Here is the error: https://pastebin.com/TRnfduE5

This is how my controller looks like:

struct PreviewController: UIViewControllerRepresentable {

    let url: URL

    @Binding var isPresented: Bool

    

    func makeUIViewController(context: Context) -> UINavigationController {

        let controller = QLPreviewController()

        controller.dataSource = context.coordinator



        controller.navigationItem.leftBarButtonItem = UIBarButtonItem(

                    barButtonSystemItem: .done, target: context.coordinator,

                    action: #selector(context.coordinator.dismiss)

                )

        

        let navigationController = UINavigationController(rootViewController: controller)

        return navigationController

    }

    

    func makeCoordinator() -> Coordinator {

        return Coordinator(parent: self)

    }

    

    func updateUIViewController(_ uiViewController: UINavigationController, context: Context) {

            let controller = QLPreviewController()

            controller.dataSource = context.coordinator

        }

    

    class Coordinator: QLPreviewControllerDataSource {

        

        let parent: PreviewController

        

        init(parent: PreviewController) {

            self.parent = parent

        }

        

        @objc func dismiss() {

            parent.isPresented = false

        }

        

        func numberOfPreviewItems(

            in controller: QLPreviewController

        ) -> Int {

            return 1

        }

        

        func previewController(

            _ controller: QLPreviewController, previewItemAt index: Int

        ) -> QLPreviewItem {

            return parent.url as QLPreviewItem

        }

        

        func previewController(_ controller: QLPreviewController, editingModeFor previewItem: QLPreviewItem

        ) -> QLPreviewItemEditingMode {

            .createCopy

        }

        

        func previewController(_: QLPreviewController, didUpdateContentsOf: QLPreviewItem){

            print("Updated.")

        }

        

        func previewController(_: QLPreviewController, didSaveEditedCopyOf: QLPreviewItem, at: URL) {

            print("Saved: " + at.path)

        }

        

    }

}

Does anyone know, what the problem is here?

And I made another experience: as you see there, I'm currently only logging the output / actions - and there isn't anything being logged, if I made just one edit. It only throws the error above after the 1st edit - so if I edit sth again and tap done or the pencil icon again... Is this ok so?

Thanks for any help or advise!

Replies

Consider the underlying error here:

Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"

This EPERM error indicates that the operation was blocked by the sandbox. For more background on this, see On File System Permissions.

The path in question is this:

/private/var/mobile/Containers/Data/PluginKitPlugin/8566EE91-9698-4282-92C3-096ED40F1DB2/tmp/NSIRD_com.apple.quicklook.extension.previewUI_pXzcPO

How did you generate that?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

  • Hi, thanks for your fast reply! I have never generated the cemetery myself it automatically created - I think! my original file is located in a fully different directory. It’s located in zoom directory in the app documents. There I created a directory myself. But I have never created such directory like in this error message.

    Do I have to create it myself?

Add a Comment

Do I have to create it myself?

I don’t think that’ll be helpful.

So, the message you posted seems to be coming from the system log. Is that right? If so, is it correlated with a particularly failure from an API that you call? If so, what is that API and how does it fail?

If it’s not correlated with a failure, I’d probably treat this as log noise.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"