Add this method to iterate over existing devices checking its position:
- (AVCaptureDevice *)frontCamera {
NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
for (AVCaptureDevice *device in devices) {
if ([device position] == AVCaptureDevicePositionFront) {
return device;
}
}
return nil;
}
Then, replace:
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
with:
AVCaptureDevice *device = [self frontCamera];
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…