【发布时间】:2020-09-17 14:25:58
【问题描述】:
以下代码在 iPhone 上运行良好。在后置摄像头和前置摄像头之间来回切换。
但是,当在 iPad 上运行它时,canAddInput-方法在选择前置摄像头时总是返回 NO(后置摄像头工作正常)。任何想法为什么?
- (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");
}
【问题讨论】:
标签: ios objective-c xcode ipad avcapturesession