From e09935125f985fc2079db8bed4b785a3a7f28549 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Thu, 14 Dec 2023 18:01:34 -0500 Subject: [PATCH] Fix copying/pasting images from Safari on macOS not working Closes #453 --- .../Sources/ComposeUI/CoreData/DraftAttachment.swift | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Packages/ComposeUI/Sources/ComposeUI/CoreData/DraftAttachment.swift b/Packages/ComposeUI/Sources/ComposeUI/CoreData/DraftAttachment.swift index 0def2175..64ecf945 100644 --- a/Packages/ComposeUI/Sources/ComposeUI/CoreData/DraftAttachment.swift +++ b/Packages/ComposeUI/Sources/ComposeUI/CoreData/DraftAttachment.swift @@ -157,10 +157,11 @@ extension DraftAttachment: NSItemProviderReading { var data = data var type = UTType(typeIdentifier)! - // this seems to only occur when the item is a UIImage, rather than just image data, - // which seems to only occur when sharing a screenshot directly from the markup screen + // the type is .image in certain circumstances: + // - macOS: image copied from macOS Safari -> only UIImage(data: data) works + // - iOS: sharing screenshot from markup -> only NSKeyedUnarchiver works if type == .image, - let image = try? NSKeyedUnarchiver.unarchivedObject(ofClass: UIImage.self, from: data), + let image = UIImage(data: data) ?? (try? NSKeyedUnarchiver.unarchivedObject(ofClass: UIImage.self, from: data)), let pngData = image.pngData() { data = pngData type = .png