Hi everyone I am trying to make a camera app. I am doing this as
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
where picker is the object of UIimagepicker Controller.
But when is run the code then the application terminates showing the error.
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Source type 1 not available'
I am using this on simulator. I know that it is not possible to check camera in simulator, but we can test for that. I think it might be that because camera is not available thats why it's terminating. But I saw an application with the same code but that was running on the simulator, just showing the camera view. Just help me out how to resolve this problem. And moreover how can I put my custom view to the camera in that app?
You need to check if the device has camera available before setting the sourcetype.
The following can check if device has camera available.
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
}
You can't check the camera functionality from your simulator. You can assign UIImagePickerControllerSourceTypePhotoLibrary
as the sourceType to test on simulator.
Swift 2.2
if UIImagePickerController.isSourceTypeAvailable(.Camera) {
imagePicker.delegate = self
imagePicker.sourceType = .Camera
presentViewController(imagePicker, animated: true, completion: nil)
} else {
print("The device has no camera")
}
Saved photos album
if UIImagePickerController.isSourceTypeAvailable(.SavedPhotosAlbum) {
imagePicker.delegate = self
imagePicker.sourceType = .SavedPhotosAlbum
imagePicker.allowsEditing = false
self.presentViewController(imagePicker, animated: true, completion: nil)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With