From 7f1247951420eae2db5b1ae3f778c4e2f5100c8a Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 8 Jul 2023 15:37:45 -0700 Subject: [PATCH] Fix not being able to share images from Shortcuts actions that have public.image and public.file-url representations Closes #420 --- ShareExtension/ShareViewController.swift | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ShareExtension/ShareViewController.swift b/ShareExtension/ShareViewController.swift index a74ab0ae..022fdefd 100644 --- a/ShareExtension/ShareViewController.swift +++ b/ShareExtension/ShareViewController.swift @@ -79,7 +79,14 @@ class ShareViewController: UIViewController { var attachments: [DraftAttachment] = [] for itemProvider in inputItem.attachments ?? [] { - if let attached: NSURL = await getObject(from: itemProvider) { + // attachments have the highest priority, but only given this heuristic + // otherwise attachment decoding ends up being overzealous + let likelyAttachment = [UTType.image, .movie].contains(where: { itemProvider.hasItemConformingToTypeIdentifier($0.identifier) }) + + if likelyAttachment, + let attachment: DraftAttachment = await getObject(from: itemProvider) { + attachments.append(attachment) + } else if let attached: NSURL = await getObject(from: itemProvider) { if url == nil { url = attached as URL } @@ -87,8 +94,6 @@ class ShareViewController: UIViewController { if text.isEmpty { text = s as String } - } else if let attachment: DraftAttachment = await getObject(from: itemProvider) { - attachments.append(attachment) } }