Similar to the answers above, but I found it easier. Show a pop-up warning if the device does not have a camera (for example, a simulator). Sam code, various uses:
//button if to take a photo - (IBAction)takePhoto:(id)sender { //checks if device has a camera if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { UIAlertView *noCameraAlert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"You don't have a camera for this device" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; //shows above alert if there no camera [noCameraAlert show]; } //otherwise, show a modal for taking a photo else { UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; imagePicker.delegate = self; imagePicker.allowsEditing = YES; imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; [self presentViewController:imagePicker animated:YES completion:NULL]; } }
source share