AVCaptureDevice isFlashModeSupported deprecated iOS 10

最后都变了- 提交于 2019-12-10 16:26:16

问题


I am using AVCaptureDevice's instance method "isFlashModeSupported" as below:

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
    }

But in iOS 10 isFlashModeSupported and setFlashMode methods are deprecated.

Xcode suggest to use AVCapturePhotoOutput's -supportedFlashModes instead.

Is any idea how to use the above method?

Thanks in advance


回答1:


Use this code. This works perfectly.

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];
}



回答2:


How is it with this?

AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

if ([device hasFlash]) {
    if ([self.stillImageOutput.supportedFlashModes containsObject:[NSNumber numberWithInt:AVCaptureFlashModeOn]]) {


}


来源:https://stackoverflow.com/questions/47135071/avcapturedevice-isflashmodesupported-deprecated-ios-10

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!