When my Share Extension receives an image from the macOS Photos app on Tahoe, the NSItemProvider passes a URL to an image file in a temporary location.
All attempts to read that file fail silently, such as with NSImage(contentsOfFile)
I can see that the file does exist in Finder.
This code did work in previous macOS versions.
It seems like a permissions issue, but startAccessingSecurityScopedResource had no effect.
Other platforms work, other apps work, such as shares from Finder, which shares via data instead of a url.
I'm really stuck. Has anyone else run into this?
// make sure provider has a conforming item
if itemProvider.hasItemConformingToTypeIdentifier(imageType)
{
do {
let data = try await itemProvider.loadItem(forTypeIdentifier: imageType, options: nil)
// data may be image NativeImage, Data, or a URL to an image file.
// figure out which by casting, then attempt to load uiImage
if let image = data as? NativeImage {
print("found NativeImage")
self.images.append(image)
}
else if let data = data as? Data {
print("found Data")
if let image = NativeImage(data: data) {
self.images.append(image)
}
} else if let url = data as? URL{
print("found URL")
if let image = NativeImage(contentsOfFile: url.path) {
print("loaded from URL")
self.images.append(image)
}
}
}catch{
print("⛔️ Share Extension Error: \(error.localizedDescription)")
}
}