objective-c – AVCaptureDevice isFlashModeSupported已弃用iOS 10

我正在使用AVCaptureDevice的实例方法“isFlashModeSupported”如下:

NSArray *captureDeviceType = @[AVCaptureDeviceTypeBuiltInWideAngleCamera,AVCaptureDeviceTypeBuiltInMicrophone];
AVCaptureDeviceDiscoverySession *captureDevice = [AVCaptureDeviceDiscoverySession discoverySessionWithDeviceTypes:captureDeviceType mediaType:AVMediaTypeVideo position:AVCaptureDevicePositionUnspecified];

NSArray *deviceList = [captureDevice devices];
AVCaptureDevice *selectedCamera = [deviceList objectAtIndex:(NSUInteger)currentCameraDeviceIndex];

if ( [selectedCamera isFlashModeSupported:AVCaptureFlashModeAuto] ){
        [selectedCamera setFlashMode:AVCaptureFlashModeAuto];   // AVCaptureFlashModeAuto
    }

但在iOS 10中,isFlashModeSupported和setFlashMode方法已被弃用.

Xcode建议使用AVCapturePhotoOutput的-supportedFlashModes.

有什么想法如何使用上述方法?

提前致谢

最佳答案 使用此代码.这非常有效.

AVCaptureSession *session = [[AVCaptureSession alloc] init];
[session setSessionPreset:AVCaptureSessionPresetPhoto];


AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
AVCaptureDeviceInput *deviceInput = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
if ([device hasFlash]) {
   [device lockForConfiguration:nil];
   device.flashMode = AVCaptureFlashModeAuto;
   [device unlockForConfiguration];
}
点赞