This is because you are opening a camera on the simulator(or on a device not having camera)…
since the code is something like [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]
and obviously, the simulator doesn’t have a camera
…
Proceed giving an alert like this,
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Device has no camera."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[myAlertView show];
}
else{
//other action
}
Swift 3:
if !UIImagePickerController.isSourceTypeAvailable(.camera) {
let alertController = UIAlertController(title: nil, message: "Device has no camera.", preferredStyle: .alert)
let okAction = UIAlertAction(title: "Alright", style: .default, handler: { (alert: UIAlertAction!) in
})
alertController.addAction(okAction)
self.present(alertController, animated: true, completion: nil)
} else {
// Other action
}
Nothing to worry, it will work on device correctly!