This is because you are opening camera on simulator... since the code is something like [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] and obviously simulator don't have 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!


You can not use the camera with the simulator only with a real device. The simulator does not have a camera even if the Mac has one.

Use the photo library instead

imagePicker.sourceType = .photoLibrary

instead of

imagePicker.sourceType = .camera

Are you trying to run the app in an iPhone emulator?

If that's the case, the emulator doesn't support camera functionality, and only supports getting photos from the photo library. Sounds like maybe I should build in an automatic fallback because lots of people will be trying to test their apps on the emulator.


The simulator won't be having camera even though you Mac has. So try using

picker.sourceType = .photoLibrary

instead of

picker.sourceType = .camera 

which will show the picture collections. But not to worry, the code will run good on the real devices.