0
votes

*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[< Ctrl 0x796991d0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key UIImagePickerControllerReferenceURL.'

@IBAction func btnReviewAction(sender : UIButton) {

    imagePicker.delegate = self
    imagePicker.mediaTypes = UIImagePickerController.availableMediaTypes(for: .photoLibrary)!
    imagePicker.modalPresentationStyle = UIModalPresentationStyle.popover

    imagePicker.preferredContentSize = CGSize(width: 1000, height: 400)
    imagePicker.allowsEditing = false
    imagePicker.isEditing = false

    appDel!.navController?.present(imagePicker, animated: true, completion: nil)

    imagePicker.popoverPresentationController?.sourceView = sender
    imagePicker.popoverPresentationController?.sourceRect = CGRect(x: 0, y: 0, width: sender.frame.size.width, height: sender.frame.size.height)
    isCaptureImage = false

}

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {

    var mediaType: String = ""
    mediaType = info[UIImagePickerControllerMediaType] as! String
    if (mediaType == (kUTTypeImage as String)) {
        if isCaptureImage == false {
            let library = ALAssetsLibrary()

            library.asset(for: value(forKey: UIImagePickerControllerReferenceURL) as! URL!, resultBlock: { (asset) -> Void in

                let original: ALAssetRepresentation? = asset?.defaultRepresentation()

                let myimag = UIImage(cgImage: original?.fullScreenImage() as! CGImage, scale: CGFloat((original?.scale())! as Float), orientation: UIImageOrientation(rawValue: 0)!)
                self.imageAddView.image = self.resizeImage(image: myimag, newWidth: 600)

            }, failureBlock: { (error) -> Void in
                print("Failed to load captured image.")

            })

            picker.dismiss(animated: true, completion: { _ in })
        }

    }
 }

Here I want to redirect PhotoGallery. and set Image on UIImmage, but I got error link above.

1
library.asset(for: value(forKey: UIImagePickerControllerReferenceURL) this line is causing the problem. The error description says it all: UIImagePickerControllerReferenceURL is not observable. - dirtydanee
Replace value(forKey: UIImagePickerControllerReferenceURL) with info[UIImagePickerControllerReferenceURL]? - Larme
Yes, but how can i fix it? - Krunal Patel

1 Answers

0
votes

I don't know why you are using ALAssetsLibrary if you just want the image try this...

public func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {

    if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {            
        self.imageAddView.image = self.resizeImage(image: image, newWidth: 600)
    }

    dismiss(animated: true, completion: nil)
}