Crear un formato de imagen con un tipo desconocido es un error UIImagePickerController (), inesperadamente encontrado nil
Swift Versión 3
Xcode versión 8.3.3 (8E3004b)
Esta pregunta ya se hizo y respondió antes. Sin embargo, no puedo encontrar una manera de corregir este error. @ "Crear un formato de imagen con un tipo desconocido es un error" con UIImagePickerController
Cuando se selecciona una nueva imagen de la Biblioteca de fotos, aparece este error
Generic Crear un formato de imagen con un tipo desconocido es un error.
Selecciono la foto y cuando toco elegir, recibo un error enfunc takePhoto
donde hago esta tareaself?.imgView.image = newImage
error fatal: se encontró inesperadamente nulo al desenvolver un valor opcional Impresión de la descripción de newImage: error producido por la expresión: error: /var/folders/s0/xq_zc7l56m1__n1qjk29p6tw0000gn/T/./lldb/2631/expr1.swift:1:80: error: uso del tipo no declarado 'UIKit' Swift._DebuggerSupport.stringForPrintObject (Swift.UnsafePointer> (bitPattern: 0x118055200) !. pointee) ^ ~~~~
typealias imagePickerHelperCompletion = ((UIImage?) -> Void)!
class ImagePickerHelper: NSObject {
weak var viewController: UIViewController!
var cameraFlashMode: UIImagePickerControllerCameraFlashMode //flash, no flash
var photoLibraryIsVisible: Bool
var cameraDevice: UIImagePickerControllerCameraDevice //front, back camera
var completion: imagePickerHelperCompletion
init(viewController: UIViewController, cameraFlashMode:UIImagePickerControllerCameraFlashMode, photoLibraryIsVisible: Bool,cameraDevice: UIImagePickerControllerCameraDevice, completion: imagePickerHelperCompletion) {
self.viewController = viewController
self.completion = completion
self.cameraFlashMode = cameraFlashMode
self.photoLibraryIsVisible = photoLibraryIsVisible
self.cameraDevice = cameraDevice
//super.init() implemented by subclasses to initializer a new object (the receiver) immediately after memory has been allocated
super.init()
self.showPhotoSourceSelection()
}
//show camera or photo library
func showPhotoSourceSelection() {
let actionSheet = UIAlertController(title: "Take new photo", message: "Would you like to open \n Camera or Photo Library?", preferredStyle: .actionSheet)
let cameraAction = UIAlertAction(title: "Camera", style: .default) { (action) in
self.showImagePicker(sourceType: .camera)
}
let photoLibraryAction = UIAlertAction(title: "Photo Library", style: .default) { (action) in
self.showImagePicker(sourceType: .photoLibrary)
}
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) { (action) in }
actionSheet.addAction(cameraAction)
if photoLibraryIsVisible == true { actionSheet.addAction(photoLibraryAction) }
actionSheet.addAction(cancelAction)
viewController.present(actionSheet, animated: true, completion: nil)
}
func showImagePicker(sourceType: UIImagePickerControllerSourceType) {
let imagePicker = UIImagePickerController()
imagePicker.allowsEditing = true //user can crop the image, or do some editing
imagePicker.sourceType = sourceType
imagePicker.mediaTypes = [kUTTypeImage as String]
imagePicker.delegate = self
if imagePicker.sourceType == .camera {
imagePicker.cameraFlashMode = cameraFlashMode
imagePicker.cameraDevice = self.cameraDevice
}
viewController.present(imagePicker, animated: true, completion: nil)
}
}//end of class
extension ImagePickerHelper: UIImagePickerControllerDelegate, UINavigationControllerDelegate {
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
viewController.dismiss(animated: true, completion: nil)
}
//if user did take a photo
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
print(info)
//prints out ["UIImagePickerControllerEditedImage": <UIImage: 0x610000294320> size {746, 498} orientation 0 scale 1.000000, "UIImagePickerControllerMediaType": public.image, "UIImagePickerControllerCropRect": NSRect: {{0, 0}, {2661, 1779}}, "UIImagePickerControllerReferenceURL": assets-library://asset/asset.JPG?id=ED7AC36B-A150-4C38-BB8C-B6D696F4F2ED&ext=JPG, "UIImagePickerControllerOriginalImage": <UIImage: 0x610000299320> size {2668, 1780} orientation 0 scale 1.000000]
if let image = info[UIImagePickerControllerEditedImage] as? UIImage {
completion(image)
viewController.dismiss(animated: true, completion: nil)
} else if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
viewController.dismiss(animated: true, completion: nil)
completion(image)
} else {
print("something is wrong line \(#line)")
}
}
}//end of extension
class ProfileViewController: UITableViewController {
var imagePickerHelper: ImagePickerHelper!
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func takePhoto(_ sender: Any) {
//create instance of ImagePickerHelper and take photo, or get it from photoLibrary
imagePickerHelper = ImagePickerHelper( viewController: self, cameraFlashMode: .auto,photoLibraryIsVisible: true, cameraDevice: .front,
completion: { [weak self] (newImage) in
})
}
}//end of class