1

I just got an isolated crash report for imagePickerController:picker: didFinishPickingMediaWithInfo with an EXC_BREAKPOINT message (which I understand typically occurs when force-unwrapping a nil value). The code that crashed is:

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

    let pickedImage = info[UIImagePickerControllerOriginalImage] as! UIImage

    dismissViewControllerAnimated(true, completion: nil)
    picker.delegate = nil

    // ...do something with pickedImage...
}

I assume I need to check that a UIImage has been returned like this:

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

    dismissViewControllerAnimated(true, completion: nil)
    picker.delegate = nil

    if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
        // ...do something with pickedImage...
    }
    else {
        // Show unsupported media type error dialog
    }
}

I have the picker media types set to image:

picker.mediaTypes = [kUTTypeImage as String]

So I am surprised didFinishPickingMediaWithInfo is returning something other than a UIImage. Any ideas why or what might be returning?

Jeshua Lacock
  • 5,730
  • 1
  • 28
  • 58
  • You should properly tag your question as Swift2 – Leo Dabus Apr 22 '17 at 00:58
  • Added swift2, but it is still swift so left the swift tag. – Jeshua Lacock Apr 22 '17 at 01:09
  • Beyond the `picker.delegate = nil`, your code is the same as mine (converted to Swift 3). Cn you duplicate the issue? If so, what if you commented out setting your controller delegate to nil? –  Apr 22 '17 at 01:31
  • 1
    Just to check, did you want info[UIImagePickerControllerOriginalImage] or info[UIImagePickerControllerEditedImage] . The edited one – shearos Apr 22 '17 at 01:35
  • Editing is disabled in the picker, so the original image, thanks. – Jeshua Lacock Apr 22 '17 at 01:56
  • @dfd I can't duplicate the issue because all I have is a crash log, and I don't know what could have been returned other than a `UIImage`. The difference in the code is I am not force-unwrapping the supplied object to a UIImage. I think it is proper practice to set any delegate to nil when it is no longer in use and don't think that is what caused the crash. – Jeshua Lacock Apr 22 '17 at 02:00
  • try my full sample of using imagePicker http://stackoverflow.com/a/43426712/4488252 – Vasily Bodnarchuk Apr 22 '17 at 07:10
  • @JeshuaLacock I'm seeing similar crash in my app. Did you figure out why you got EXC_BREAKPOINT ? – Kazuki Mar 18 '20 at 05:29
  • I was never able to definitively solve the issue because I could not reproduce it. All I had was the crash log. – Jeshua Lacock Mar 19 '20 at 06:04

0 Answers0