Implement a Thumbnail Extension to allow the operating system and other apps to display thumbnails of your custom files.
Add a Thumbnail Extension to your app to enable other apps to create thumbnails of your custom file types using the
QLThumbnail object. In addition, this allows the operating system to display rich thumbnails for your custom file types instead of a generic file icon. For example, if your app implements a Thumbnail extension, the iOS Files app and Finder on macOS display thumbnails for your custom file types when the user installs your app.
Adding a Thumbnail Extension also enables iCloud to generate a thumbnail alongside your custom file, enabling other devices to display the thumbnail once the file has been synced with iCloud.
Add a Thumbnail Extension to Your App
To add a Thumbnail Extension to your app, select your project in Xcode’s Project navigator and make sure the General pane is visible. Select the + button and add a new Thumbnail extension to your app. Make sure to allow Xcode to create and activate a new build scheme for the extension.
In addition to the new scheme for the Thumbnail extension, Xcode adds the following files to your project:
A new group in the Project navigator for the extension.
QLThumbnailsubclass that contains the code to generate a thumbnail representation of your custom file types.
Infowith information about the custom file types to associate with your app and the thumbnails' minimum dimension.
Update the Extension’s Info.plist
Xcode creates an
Info for your new Thumbnail Extension that contains two important entries below the
NSExtension key. Update the following entries in the
This entry contains an array of all custom file types for which your app provides thumbnails. Make sure to declare all file types that you support, using the exact Uniform Type Identifiers (UTI). QuickLookThumbnailing only uses your extension for a file type if the listed UTI matches the file type. It’s not sufficient to list a parent UTI to which a file type may conform.
Some content types, such as text-heavy content, may not present a good representation at very small sizes. The value of this entry describes the minimum dimension of the thumbnails that your Thumbnail Extension provides, instructing the QuickLookThumbnailing framework to avoid calling your extension if an app or operating systems requests a thumbnail smaller than the specified size, and instead provide a generic file icon.
Create Thumbnails for Your Custom File Types
Using Xcode’s Thumbnail Extension template adds a subclass of
QLThumbnail to your project that contains an empty implementation of the
provide method. Decide which of
QLThumbnail’s initializers you want to use and add your implementation to create thumbnails for each
QLThumbnail. This decision depends on your app and its requirements; make sure to optimize your code that generates the thumbnails and keep any files as small as possible.