IOS-闪光灯操作

时间:2022-06-12 07:34:13
AVCaptureDevice.h主要用来获取iphone一些关于相机设备的属性。
前置和后置摄像头
enum {
AVCaptureDevicePositionBack = ,
AVCaptureDevicePositionFront =
};
typedef NSInteger AVCaptureDevicePosition; 闪光灯开关 enum {
AVCaptureFlashModeOff = ,
AVCaptureFlashModeOn = ,
AVCaptureFlashModeAuto =
};
typedef NSInteger AVCaptureFlashMode; 手电筒开关 enum {
AVCaptureTorchModeOff = ,
AVCaptureTorchModeOn = ,
AVCaptureTorchModeAuto = ,
};
typedef NSInteger AVCaptureTorchMode; 焦距调整 enum {
AVCaptureFocusModeLocked = ,
AVCaptureFocusModeAutoFocus = ,
AVCaptureFocusModeContinuousAutoFocus = ,
};
typedef NSInteger AVCaptureFocusMode; 曝光量调节 enum {
AVCaptureExposureModeLocked = ,
AVCaptureExposureModeAutoExpose = ,
AVCaptureExposureModeContinuousAutoExposure = ,
};
typedef NSInteger AVCaptureExposureMode; 白平衡 enum {
AVCaptureWhiteBalanceModeLocked = ,
AVCaptureWhiteBalanceModeAutoWhiteBalance = ,
AVCaptureWhiteBalanceModeContinuousAutoWhiteBalance = ,
};
typedef NSInteger AVCaptureWhiteBalanceMode;

开启闪光灯:

 AVCaptureDevice* d = nil; // find a device by position
NSArray* allDevices = [AVCaptureDevice devices];
for (AVCaptureDevice* currentDevice in allDevices) {
if (currentDevice.position == AVCaptureDevicePositionBack) {
d = currentDevice;
}
} // at this point, d may still be nil, assuming we found something we like....
NSError* err = nil;
BOOL lockAcquired = [d lockForConfiguration:&err];
if (!lockAcquired) {
// log err and handle...
} else {
// flip on the flash mode
if ([d hasFlash] && [d isFlashModeSupported:AVCaptureFlashModeOn] ) {
[d setFlashMode:AVCaptureFlashModeOn];
}
[d unlockForConfiguration];
}