CactiApp CactiApp - 1 month ago 19
Swift Question

Image picker crash on simulator

I made an app on Xcode 7.3. Today I installed XCode8 and I changed something on code then I see this crash when I hit Photo Library Button on the simulator. After this I have tried on the iPhone 6 and it works well. I have no idea why. I need to develop app but I can't. Just because of the simulator error. It's so interesting.

This is the crash screen:

the crash screen

This is my code for Photo Library:

@IBAction func PhotoLibraryAction(_ sender: UIButton) {
let picker = UIImagePickerController()
picker.delegate = self
picker.sourceType = .photoLibrary

present(picker, animated: true, completion: nil)
}

@IBAction func CameraAction(_ sender: UIButton) {
let picker = UIImagePickerController()
picker.delegate = self
picker.sourceType = .camera

present(picker, animated: true, completion: nil)
}

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {

if var image = info[UIImagePickerControllerOriginalImage] as? UIImage {
ImageDisplay.image = image
}
dismiss(animated: true, completion: nil)
}

Zeb Zeb
Answer

Try to add this to your plist:

<key>NSPhotoLibraryUsageDescription</key>
<string>This app requires access to the photo library.</string>
<key>NSCameraUsageDescription</key>
<string>This app requires access to the camera.</string>