Fix copying/pasting images from Safari on macOS not working

Closes #453
This commit is contained in:
Shadowfacts 2023-12-14 18:01:34 -05:00
parent e8ef9345e9
commit e09935125f
1 changed files with 4 additions and 3 deletions

View File

@ -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