I am trying to use the PHPickerViewController to select images from my photo gallery and seeing the following error.
Could not create a bookmark: NSError: Cocoa 257 "The file couldn’t be opened because you don’t have permission to view it
I am using Xcode 12.5 on Mac M1 (macOS 11.2.3) And connecting to an iPhone 12 (IOS 14.8).
The code in question
private func getPhoto(from itemProvider: NSItemProvider) {
print(itemProvider.registeredTypeIdentifiers)
itemProvider.loadFileRepresentation(forTypeIdentifier: UTType.image.identifier) { url, error in
if let error = error {
print("Encountered Error in loadFileRepresentation \(error.localizedDescription)")
}
if url != nil {
print("Obtained url: \(String(describing: url))")
} else {
print("Could not obtain url")
}
let imageData = try! Data(contentsOf: url!)
DispatchQueue.main.async {
self.parent.mediaItems.append(item: PhotoPickerItem(with: UIImage(data:imageData)!))
}
}
}
}
I can see that the itemProvider has the following representations.
["public.heic", "public.jpeg"]
and I have tried UTType.jpeg.identifier as well.