Reputation: 9660
I have following code to open the photo library or camera but whenever I run the code I get a runtime error:
WhatsUp[28458:10570522] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSDictionaryM setObject:forKey:]: object cannot be nil (key: _UIImagePickerControllerMediaTypes)'
*** First throw call stack:
Here is my code:
// open the camera
self.imagePicker = UIImagePickerController(rootViewController: self)
self.imagePicker.delegate = self
if UIImagePickerController.isSourceTypeAvailable(.camera) {
self.imagePicker.sourceType = .camera
} else {
self.imagePicker.sourceType = .photoLibrary
}
self.present(self.imagePicker, animated: true, completion: nil)
I have already added the privacy keys to the info.plist file as shown below:
Upvotes: 3
Views: 1470
Reputation: 318774
You are using the inherited UINavigationController
initializer when creating your image picker. But the proper way is to use the initializer with no arguments.
The line:
self.imagePicker = UIImagePickerController(rootViewController: self)
needs to be:
self.imagePicker = UIImagePickerController()
By using the wrong initializer the image picker isn't setup correctly.
Upvotes: 8