PHPickerViewController: Permission Error

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.

Have you setup Privacy things properly in your Info.plist?

I'll check. Thanks for the pointer.

From what I can tell using this controller, gives you the advantage that you don't need to seek permission(at least nothing seems to be required on info.plist)

https://developer.apple.com/documentation/photokit/delivering_an_enhanced_privacy_experience_in_your_photos_app With the many privacy enhancements added in iOS 14, it’s a good time to evaluate how and why your app uses PhotoKit to access the user’s library. Many apps may only need read-only access to retrieve images to share on the internet or embed in a document or email. For these purposes, the simplest way to provide an enhanced user experience is to use PHPickerViewController to access the Photos library.  PHPickerViewController is a new picker that replaces UIImagePickerController. Its user interface matches that of the Photos app, supports search and multiple selection of photos and videos, and provides fluid zooming of content. Because the system manages its life cycle in a separate process, it’s private by default. **The user doesn’t need to explicitly authorize your app to select photos, which results in a simpler and more streamlined user experience. **

@pradnyc, so, how have you interpreted the description?

I have added the key to my info.plist. but that doesn't seem to help.

PHPickerViewController: Permission Error
 
 
Q