Xcode 8 - swift 3: Creating an image format with an unknown type - error

I get an error when selecting an image using UIImagePicker:

[Generic] Creating an image format with an unknown type is an error 

I use Xcode 8.1 and Swift 3. I have already searched all over the Internet, but it seems that nothing solves my problem, please help!

Here it is my code:

 class TabBarController: UITabBarController, UIImagePickerControllerDelegate, UINavigationControllerDelegate { var isSelected: Bool = false var imgPicker: UIImagePickerController = UIImagePickerController() override func viewDidLoad() { super.viewDidLoad() //imgPicker = UIImagePickerController() imgPicker.delegate = self imgPicker.allowsEditing = false imgPicker.sourceType = .photoLibrary } func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) { imgPicker.dismiss(animated: true, completion: nil) if let image = info[UIImagePickerControllerOriginalImage] as? UIImage { self.performSegue(withIdentifier: "toPostPicture", sender: image) } } func imagePickerControllerDidCancel(_ picker: UIImagePickerController) { dismiss(animated: true, completion: nil) } func askImagePickerSource(sender: UIViewController) { if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera) { let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet) let cameraAction = UIAlertAction(title: "Camera", style: .default, handler: { (action: UIAlertAction) in self.imgPicker.sourceType = .camera self.imgPicker.mediaTypes = UIImagePickerController.availableMediaTypes(for: .camera)! sender.present(self.imgPicker, animated: true, completion: nil) }) let photoLibraryAction = UIAlertAction(title: "Photo Library", style: .default, handler: { (action: UIAlertAction) in self.imgPicker.mediaTypes = UIImagePickerController.availableMediaTypes(for: .photoLibrary)! sender.present(self.imgPicker, animated: true, completion: nil) }) let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) { (UIAlertAction) in sender.dismiss(animated: true, completion: nil) } alert.addAction(cameraAction) alert.addAction(photoLibraryAction) alert.addAction(cancelAction) sender.present(alert, animated: true, completion: nil) } else { self.imgPicker.mediaTypes = UIImagePickerController.availableMediaTypes(for: .photoLibrary)! sender.present(self.imgPicker, animated: true, completion: nil) } } override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if segue.identifier == "toPostPicture" { if let postPictureVC = segue.destination as? PostPictureVC { if let image = sender as? UIImage { postPictureVC.image = image } } } } 

}

+5
source share
2 answers

I ran into the same problem without adding a delegate as " self " for the UIImagePickerController. After adding, I was able to get the selected image from the gallery. But even after adding the delegate as self and accessing the image (Display on ImageView), I still got the same error. After further research on SO, I found out that this is just a mistake and has no effect on the application.

See also "Creating an image format with an unknown type is an Objective-C Xcode 8 error"

+3
source

Can you send the .debugDescription the info parameter to the delegate of your collector?

 func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) { print(info.debugDescription) ... } 
0
source

Source: https://habr.com/ru/post/1259057/


All Articles