5

My document browser-based test app is working fine. It shows the browser. It has a special exported document type. I can create files of that type, I can open files of that type.

There's just one problem. My app also includes a Thumbnail Extension. As far as I can tell, that extension's single method (the override of QLThumbnailProvider provideThumbnail(for:_:)) is never being called. So my files, as shown in the document browser, the Files app, etc., do not have the correct thumbnail.

Has anyone gotten thumbnail extensions to work in iOS 13? I'm testing on a device (because document browser apps don't work on the simulator).

Here are my Info.plist settings. First, the app. Here's the part where we define the document type and export the UTI:

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeIconFiles</key>
        <array/>
        <key>CFBundleTypeName</key>
        <string>PeopleGroup2</string>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>LSHandlerRank</key>
        <string>Owner</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>com.neuburg.pplgrp2new</string>
        </array>
    </dict>
</array>
<key>UTExportedTypeDeclarations</key>
<array>
    <dict>
        <key>UTTypeConformsTo</key>
        <array>
            <string>public.content</string>
            <string>public.data</string>
        </array>
        <key>UTTypeDescription</key>
        <string>PeopleGroup2</string>
        <key>UTTypeIconFiles</key>
        <array/>
        <key>UTTypeIdentifier</key>
        <string>com.neuburg.pplgrp2new</string>
        <key>UTTypeTagSpecification</key>
        <dict>
            <key>public.filename-extension</key>
            <string>pplgrp2new</string>
        </dict>
    </dict>
</array>

And here's the key part of the Thumbnail Extension Info.plist:

<key>NSExtension</key>
<dict>
    <key>NSExtensionAttributes</key>
    <dict>
        <key>QLSupportedContentTypes</key>
        <array>
            <string>com.neuburg.pplgrp2new</string>
        </array>
        <key>QLThumbnailMinimumDimension</key>
        <integer>10</integer>
    </dict>
    <key>NSExtensionPointIdentifier</key>
    <string>com.apple.quicklook.thumbnail</string>
    <key>NSExtensionPrincipalClass</key>
    <string>$(PRODUCT_MODULE_NAME).ThumbnailProvider</string>
</dict>

As you can see, the thumbnail extension supported content type matches the app's exported UTI. But the ThumbnailProvider code is apparently not being called.

Here's the thumbnail provider code, just a rock-bottom test:

@objc class ThumbnailProvider: QLThumbnailProvider {
    override func provideThumbnail(for request: QLFileThumbnailRequest, 
        _ handler: @escaping (QLThumbnailReply?, Error?) -> Void) {
            let url = Bundle.main.url(forResource: "smiley", withExtension: "jpg")!
            let reply = QLThumbnailReply(imageFileURL: url)
            handler(reply, nil)
    }
}

But it doesn't seem to be called.

Could someone show me an example that actually works?

The actual test project is here:

https://github.com/mattneub/Programming-iOS-Book-Examples/tree/master/bk2ch23p810DocumentBrowser

EDIT: The release of iOS 13.2 has not magically made this start working.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • 1
    `QLThumbnailProvider` is broken when the respective app extension is compiled with Xcode 11. I have a similar problem and tried compiling Apple's own [Particles sample app](https://developer.apple.com/documentation/uikit/view_controllers/building_an_app_based_on_the_document_browser_view_controller) with both Xcode 11 and Xcode 10.3 of Xcode. The sample app uses `UIDocumentBrowserViewController`, `UIDocument` and `QLThumbnailProvider` as well. I was only able to get a working thumbnail using Xcode 10.3 (iOS 12 on device, iOS 12 + 13 on the simulator). – Daniel Oct 27 '19 at 22:29

2 Answers2

1

Since iOS13, there a new QuickLookThumbnailing.framework that handles thumbnailing for iOS and macOS. Make sure that it is linked by your extension or you will get a silent crash when dyld will try to load the framework.

libe
  • 11
  • 3
  • My thumbnail provider extension both links to and imports QuickLookThumbnailing framework. All of that happens automatically when you create a thumbnail extension. It is true that Apple's Particle app crashes silently in the way you describe, but mine does not. I'm not asking about their app; I'm asking about mine. To help me, download my project and make the thumbnail extension start working somehow. :) And tell me how you did it. :)))) – matt Nov 06 '19 at 18:42
0

I know the question is very old, and I apologize in advance if my suggestion is too obvious, but have you checked that smiley.jpg has the correct target membership? It should a member of the thumbnail extension target. I haven't tried this with your example, but in my own setting, I found that if the membership is set, for example, to the main app and not to the extension, your problem crops up. Hope this helps. By the way, I wasted an inordinate amount of time trying to make QLThumbnailProvider work with QLThumbnailReply(contextSize:currentContextDrawing:), to no avail. What a PITA. The other initializers worked OK.

Torrontés
  • 145
  • 7