I have the method, that take photos from gallery or from the camera
-(IBAction) getPhoto:(id) sender {
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
if((UIButton *) sender == choosePhotoBtn) {
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
} else {
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
[self presentModalViewController:picker animated:YES];
}
But when i run it on the simulator, code doesnt work. And it doesnt work in picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum
and picker.sourceType = UIImagePickerControllerSourceTypeCamera
Is the problem in the simulator or in the code?
Similarly to the above answers, but I found this easier. Show a pop up alert if the device doesn't have a camera (like the simulator). Sam code, different usage:
In simulator your picker.sourceType = UIImagePickerControllerSourceTypeCamera wont be called as there is no camera available in simulator. Also its a good practice to check whether the source type is available to avoid crashes.
Try this,
If you are creating the app for iPad. You will have to present the gallery in a popOver control.
Swift 2.2 version:
Swift 3.0 verison:
In simulator, you should also not set
cameraCaptureMode
norshowsCameraControls
.