The following code is working perfectly on the iPhone. Switching back and forth between back- and front-camera.
However, when run it on an iPad the canAddInput-method always returns NO when selecting the front-camera (back camera works fine). Any ideas why?
- (void)addVideoInput:(BOOL)isFront{
AVCaptureDevice *videoDevice;
//NSLog(@"Adding Video input - front: %i", isFront);
[self.captureSession removeInput:self.currentInput];
if(isFront == YES){
self.isFrontCam = YES;
videoDevice = [self frontFacingCameraIfAvailable];
}else{
self.isFrontCam = NO;
videoDevice = [self backCamera];
}
if (videoDevice) {
NSError *error;
AVCaptureDeviceInput *videoIn = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:&error];
if (!error) {
// Everything's fine up to here.
// the next line always resolves to NO and thus the
// Video input isn't added.
if ([[self captureSession] canAddInput:videoIn]){
[[self captureSession] addInput:videoIn];
self.currentInput = videoIn;
// Set the preset for the video input
if([self.captureSession canSetSessionPreset:AVCaptureSessionPreset1920x1080]){
[self.captureSession setSessionPreset:AVCaptureSessionPreset1920x1080];
}
}
else {
NSLog(@"Couldn't add video input");
NSLog(@"error: %@", error.localizedDescription);
}
}
else{
NSLog(@"Couldn't create video input");
NSLog(@"error: %@", error.localizedDescription);
}
}else
NSLog(@"Couldn't create video capture device");
}