ios开发之手电筒使用补充

今天看自己之前的scanning,发现对于照明说的不是很清楚,这里重新写一次,也做收藏

#import <AVFoundation/AVFoundation.h>   //需要引用框架

- (void)lightSwitch:isOn{

AVCaptureDevice *captureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; //创建Video类型的驱动对象用于启动手电筒

   if (![captureDevice hasTorch]) return;  //检测是否有灯光

    if(![captureDevice hasFlash])  return; //检测是否有灯光

    [captureDevice lockForConfiguration:nil];

//  官方解释,必须要持一个设备锁  --------In order to set hardware properties on an AVCaptureDevice, such as focusMode and exposureMode, clients must first acquire a lock on the device. Clients should only hold the device lock if they require settable device properties to remain unchanged. Holding the device lock unnecessarily may degrade capture quality in other applications sharing the device.

    isOn = !isOn;

    captureDevice.torchMode = isOn? AVCaptureTorchModeOn:AVCaptureTorchModeOff;

    [captureDevice unlockForConfiguration];

}

posted @ 2017-03-31 11:55  象棋中的象棋  阅读(467)  评论(0编辑  收藏  举报