0

I'm making a basic iPhone only image editing app. The imagePickerController runs fine on all iPhones and iPads (in iPhone compatibility mode) running IOS 10 in the simulator, and all iPhones on IOS 9, but:

iPads in iPhone compatability mode on iOS 9 crash when an image is chosen from the picker. The debug console says the reason of the crash is:

fatal error: unexpectedly found nil while unwrapping an Optional value

 func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any])
    image = info[UIImagePickerControllerOriginalImage] as! UIImage
}

In the code above, the first line inside the imagePickerController function is where the crash occurs.

My plist permissions are set correctly, and I shouldn't need to set the picker into a popover because its running in iPhone compatibility mode and also it works normally on iOS 10 iPads (in iPhone compatibility mode).

I'm running all of these tests in the simulator if that has any bearing, but I haven't been able to find a rhyme or reason for this iOS 9 specific crash. Any advice would be greatly appreciated.

genericguy25
  • 602
  • 3
  • 16
  • Can you verify that `info[UIImagePickerControllerOriginalImage]` actually returns a `UIImage`? – JAL Feb 01 '17 at 20:06
  • 1
    Clearly the error means there is no original image in the `info` dictionary. – rmaddy Feb 01 '17 at 20:06
  • 1
    Code *defensively*. Use a conditional downcast rather than a forced downcast. You will still have a question as to why an image wasn't picked but at least your app won't crash – Paulw11 Feb 01 '17 at 20:07
  • My verification is based on all iPhones working on iOS 9 and 10, and all iPads in compatibility mode working on iOS 10. – genericguy25 Feb 01 '17 at 20:18
  • Try accessing the `info` dictionary **after** dismissing the `UIImagePickerController` – crizzis Feb 01 '17 at 20:32
  • Thanks for the idea, I tried it but it crashes still in the same way. – genericguy25 Feb 01 '17 at 20:44
  • In my experience, I was getting blank thumbnails like these http://stackoverflow.com/questions/36289929/uiimagepickercontroller-does-not-work-correct-on-ios-9-3-ipad-4 so might be related. They fixed it in iOS 10. – paiv Feb 01 '17 at 20:45
  • this seems to be exactly what is going on. Doesn't seem to be a fix for iOS 9.0 unfortunately. – genericguy25 Feb 01 '17 at 20:54
  • @genericguy25 comments mention `iCloud Photo Library` setting. This works as a workaround. – paiv Feb 01 '17 at 20:58
  • Thanks, turning this on in the simulator crashes the settings app strangely. – genericguy25 Feb 01 '17 at 21:01

0 Answers0