Quick Look Preview Extension works on macOS but not iOS

Hi,

I have a document-based SwiftUI multiplatform app, where the document is saved as JSON. Obviously I don't want Quick Look to show the JSON of my file, so I made a Quick Look Preview extension for each platform.

The macOS one works… okay, sometimes it's tricky to test and I need to use qlmanage to empty the cache or to show the preview, but it does work. I can even debug it.

But the iOS one just never seems to be run. If I show Quick Look in the Files app on iOS, or if I AirDrop a file from my app to my iPhone, it shows as JSON, with an option to open it in my app. If I run the iOS Preview Extension in the debugger and launch the Files app, and then try to use Quick Look in a file there, it shows the JSON and the debugger just stays in the state 'Waiting to Attach'.

The preview extensions are not data based; in both of them I have implemented

func preparePreviewOfFile(at url: URL) async throws

in PreviewViewController.swift. Pretty much the same code except one is using a UIHostingController and the other is using an NSHostingController. The only difference in the Info.plists for the two extensions is that the iOS one uses NSExtensionMainStoryboard while the macOS one uses NSExtensionPrincipalClass. This is how they were set up when I created them from the relevant Quick Look Preview Extension templates.

I made a sample project with a much simpler document, UI, etc. and I have the same issue there. The macOS preview works, the iOS one never runs. I have checked that the correct preview extension is embedded in the target for each OS (under Embed Foundation Extensions in the Build Phases)

Is there anything I need to do differently in iOS, or anything I might have inadvertently got wrong? Is there a way to run something similar to qlmanage on iOS, since that sometimes seems to help on macOS?

Incidentally, I have also added Quick Look Thumbnail extensions, and they work on both platforms.

Answered by Engineer in 846707022

How is your document type set up? Did you make a new content type conforming to public.json?

Accepted Answer

How is your document type set up? Did you make a new content type conforming to public.json?

I had made a new content type but it was conforming to public.plain-text (which I think was the default in the template.) I didn't know public.json was an option! I changed it to public.json and it works now. Thanks! It's interesting that it worked on macOS with public.plain-text but not on iOS. (Sorry for making this a reply; I tried to add this as a comment on the other reply but got an error)

Quick Look Preview Extension works on macOS but not iOS
 
 
Q