0

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 appears to throw the above exception in the call to loadFileRepresentation. I have also tried loadInPlaceFileRepresentation and loadObject with similar results.

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.

Any pointers would be greatly appreciated

Pradyot
  • 2,897
  • 7
  • 41
  • 58
  • Does [this](https://stackoverflow.com/questions/69748225/how-to-ask-permissions-for-camera-and-gallery-at-the-same-time-in-ios) answer your question? – Yrb Nov 11 '21 at 15:25
  • https://developer.apple.com/documentation/photokit/delivering_an_enhanced_privacy_experience_in_your_photos_app The user doesn’t need to explicitly authorize your app to select photos, which results in a simpler and more streamlined user experience. – Pradyot Nov 11 '21 at 18:50
  • You still need a key in the Info.plist – Yrb Nov 11 '21 at 19:05

0 Answers0