ios - 我正在尝试切换此代码以使用前置摄像头
<p><p>我是编程新手,并试图修复此代码以使用前置摄像头而不是默认使用后置摄像头。我不确定我需要进行哪些更改才能使其正常工作。</p>
<p>这是我的示例代码:</p>
<pre><code>-(void)viewWillAppear:(BOOL)animated{
session = [ init];
;
AVCaptureDevice *inputDevice = ;
NSError *error;
AVCaptureDeviceInput *deviceInput = ;
if () {
;
}
AVCaptureVideoPreviewLayer *previewLayer = [initWithSession:session];
;
CALayer *rootLayer = [ layer];
;
CGRect frame = self.frameForCapture.frame;
;
;
stillImageOutput = [ init];
NSDictionary *outputSettings = [ initWithObjectsAndKeys:AVVideoCodecJPEG, AVVideoCodecKey, nil];
;
;
;
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>替换这个:</p>
<pre><code>AVCaptureDevice *inputDevice = ;
NSError *error;
AVCaptureDeviceInput *deviceInput = ;
</code></pre>
<p>有了这个:</p>
<pre><code>NSArray *devices = ;
AVCaptureDevice *frontCamera;
for (AVCaptureDevice *dev in devices) {
if (dev.position == AVCaptureDevicePositionFront) {
frontCamera = dev;
break;
}
}
if (!frontCamera) {
NSLog(@"No front camera found!");
// Handle no front camera error
}
NSError *error;
AVCaptureDeviceInput *input = ;
</code></pre></p>
<p style="font-size: 20px;">关于ios - 我正在尝试切换此代码以使用前置摄像头,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/27638792/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/27638792/
</a>
</p>
页:
[1]