Error Domain=NSItemProviderErrorDomain Code=-1000 "Cannot load representation of type public.jpeg"

Viewed 2432

I am using PHPickerViewController for image picking from the photo library instead of UIImagePickerController. When I use this code I couldn't get the image from already picked image.

Error Domain=NSItemProviderErrorDomain Code=-1000 "Cannot load representation of type public.jpeg" UserInfo={NSLocalizedDescription=Cannot load representation of type public.jpeg, NSUnderlyingError=0x60000080fb70 {Error Domain=NSCocoaErrorDomain Code=256 "The file “[...].jpeg” couldn’t be opened." UserInfo={NSURL=file: [...].jpeg, NSFilePath= [...].jpeg, NSUnderlyingError=0x600000814b70 {Error Domain=NSOSStatusErrorDomain Code=-10817 "(null)"}}}})

func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {
        dismiss(animated: true, completion: nil)
        
        if let itemProvider = results.first?.itemProvider, itemProvider.canLoadObject(ofClass: UIImage.self) {
            itemProvider.loadObject(ofClass: UIImage.self) { [weak self] image, error in
                DispatchQueue.main.async {
                    guard let self = self, let image = image as? UIImage else {
                        return
                    }
                }
            }
        }
    }
0 Answers
Related