打开或者关闭iphone设备闪关灯的oc代码

通过以下代码可以调用闪光灯的打开和关闭状态。
//打开
-(void)turnOnLed {   
 AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];        
 if ([device hasTorch]) {       
  [device lockForConfiguration:nil];       
  [device setTorchMode: AVCaptureTorchModeOn];       
  [device unlockForConfiguration];          
 }   
} 
//关闭
-(void)turnOffLed {   
 AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];     
 if ([device hasTorch]) {       
  [device lockForConfiguration:nil];       
  [device setTorchMode: AVCaptureTorchModeOff];       
  [device unlockForConfiguration];     
 }   
posted @ 2016-03-24 11:27  Sunny孙宁  阅读(459)  评论(0编辑  收藏  举报