问题
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