此类不是密钥值编码兼容的密钥

时间:2017-05-16 13:29:09

标签: ios

  

***由于未捕获的异常'NSUnknownKeyException'而终止应用,原因:'[< Ctrl 0x796991d0> valueForUndefinedKey:]:此类不是键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 })
        }

    }
 }

这里我想重定向PhotoGallery。并在UIImmage上设置了图片,但我上面有错误链接。

1 个答案:

答案 0 :(得分:0)

如果您只是想让图片试试这个,我不知道您使用ALAssetsLibrary的原因......

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)
}