ios开发之手电使用补充

Posted 象棋中的象棋

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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];

}

以上是关于ios开发之手电使用补充的主要内容,如果未能解决你的问题,请参考以下文章

Unity3D发布打包系列之——IOS真机调试打包ipa(补充)

IOS开发之UI布局

iOS开发底层之RuntimeObjc_msgSend探究下 - 09

iOS开发底层之RuntimeObjc_msgSend探究下 - 09

iOS开发底层之RuntimeObjc_msgSend探究 - 08

iOS开发底层之RuntimeObjc_msgSend探究 - 08