QLPreviewReplyAttachment
An attachment for a Quick Look preview reply that provides additional content for the system to display a preview.
Declaration
class QLPreviewReplyAttachmentOverview
When providing a data-based Quick Look preview with HTML, use QLPreviewReplyAttachment to include images, CSS, and other linked content in the HTML of the preview.
Reference content in your HTML using the CID notation for the reference. For example, if your HTML preview response includes an image, create a QLPreviewReplyAttachment with the image, add it to the reply’s attachments with an associated string, and reference the image with the associated string, prefixed by cid:. The following example illustrates returning HTML as a preview reply with an image as an attachment:
let reply = QLPreviewReply(dataOfContentType: .html,
contentSize: CGSize(width: 750, height: 500)) { htmlReply in
let content = """
<html>
<head></head>
<body>
<h1>Preview</h1>
<img src="cid:exampleImage" width="400">
</body>
</html>
"""
guard let contentData = content.data(using: .utf8) else {
throw PreviewError.previewSetupFailure("Unable to encode preview content")
}
guard let imageFileURL = Bundle.main.url(forResource: "yourImage",
withExtension: "jpg") else {
throw PreviewError.previewSetupFailure("unable to load image")
}
let imageData = try Data(contentsOf: imageFileURL)
htmlReply.attachments["exampleImage"] = QLPreviewReplyAttachment(data: imageData,
contentType: .jpeg)
return contentData
}
reply.title = "HTML Preview Example"