Reputation: 75
I've got a custom view controller I'm using which has a pair of buttons, one to take a photo and one to choose a photo. When you choose photo, it shows the camera roll without issue. However, when you choose take photo, it still shows the camera roll - or the photo stream or anything other than the actual camera, even though I'm using an iPhone with the camera perfectly functional.
- (IBAction)getPhoto:(id)sender
{
[self makeUIImagePickerControllerForCamera:NO];
}
- (IBAction)takePhoto:(id)sender
{
[self makeUIImagePickerControllerForCamera:YES];
}
- (void) makeUIImagePickerControllerForCamera:(BOOL)camera
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
if (camera) {
NSLog(@"!!! Show camera");
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
} else {
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
}
[picker setMediaTypes:[NSArray arrayWithObjects:(NSString *) kUTTypeImage, nil]];
[self presentModalViewController: picker animated: YES];
}
The code above is exactly what I'm using. I simply need to get the camera to actually show, somehow. Thanks!
*Note: I'm using iOS 5 and ARC.
Upvotes: 3
Views: 1426
Reputation: 16714
If you are not already, you should check to make sure that the camera is in fact available on the current device. If it's not, the "takePhoto" action should not be accessible to the user. You can do that like this:
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
// ... enable camera
} else {
// ... only enable the user to select from their photo album
}
Upvotes: 0
Reputation: 5940
This might be too obvious but just want to make sure we are covering the basics. You ARE trying this on a device, and not the simulator correct? The simulator will always only pull up the camera roll if the camera is supposed to show.
Upvotes: 4