Reputation: 16138
I have an iPad app that should use only the front camera on the device,
the problem is that after I take the first picture with the front camera, if the user chooses to retake a photo, then the back camera is used, and if retake again it uses the correct front camera,
I release the imagePicker and and the pop over that shows my camera preview and image, every time the take pic is tapped.
- (void)setUpImagePicker
{
//poner photo picker en pop up!
BOOL hasCamera = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = hasCamera ? UIImagePickerControllerSourceTypeCamera : UIImagePickerControllerSourceTypePhotoLibrary;
picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
[picker setShowsCameraControls:FALSE];
CGAffineTransform translate = CGAffineTransformMakeTranslation(0.0, 0.0);
picker.cameraViewTransform = translate;
CGAffineTransform scale = CGAffineTransformScale(translate, 1, 1);
picker.cameraViewTransform = scale;
self.companyPopOverController = [[[UIPopoverController alloc] initWithContentViewController:picker] autorelease];
self.companyPopOverController.passthroughViews=[NSArray arrayWithObject:self.view];
[self createTimer];
}
- (NSTimer*)createTimer {
// create timer on run loop
return [NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:@selector(timerTicked:) userInfo:nil repeats:NO];
}
- (void)timerTicked:(NSTimer*)timer {
[self.companyPopOverController presentPopoverFromRect:CGRectMake(622, 534, 10, 10) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
}
- (void)takePicButtonPressed:(id)sender
{
NSLog(@"takePicButtonPressed");
if (!self.retakePic) {
NSLog(@"retake no");
self.retakePic = YES;
self.imageTaken = YES;
[self.takePicButton setImage:[UIImage imageNamed:@"takePicButton_Re"] forState:UIControlStateNormal];
[picker takePicture];
return;
}else {
NSLog(@"retake is yes");
self.retakePic = NO;
self.imageTaken = NO;
picker = nil;
[picker release];
self.companyPopOverController = nil;
[self.companyPopOverController release];
[self setUpImagePicker];
//button image, take
[self.takePicButton setImage:[UIImage imageNamed:@"takePicButton"] forState:UIControlStateNormal];
return;
}
}
So how can I make sure that my app only uses the front camera?
thanks!
Upvotes: 0
Views: 1575
Reputation: 772
This is a bit of a work around, but because there is no delegate for what you're looking for this will do the trick.
Sign up notifications from the PickerController in ViewDidLoad (In this case because you implement your own controls you may have to setup your own notification)
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(retakeImage:)
name:@"_UIImagePickerControllerUserDidRejectItem" object:nil];
Then when the user chooses to retake the photo reassert the picker to use the front camera.
- (void)retakeImage:(NSNotification *)notification
{
self.pickerController.cameraDevice = UIImagePickerControllerCameraDeviceFront;
}
Hope this helps!
Upvotes: 3