[Objective-C] 用代码打开IOS设备(iphone)的闪光灯 →→→→→进入此内容的聊天室

来自 , 2021-02-12, 写在 Objective-C, 查看 116 次.
URL http://www.code666.cn/view/6e01383f
  1.     AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
  2.        
  3.         if (device.torchMode == AVCaptureTorchModeOff)
  4.         {
  5.                 // Create an AV session
  6.                 AVCaptureSession *session = [[AVCaptureSession alloc] init];
  7.                
  8.                 // Create device input and add to current session
  9.                 AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error: nil];
  10.                 [session addInput:input];
  11.                
  12.                 // Create video output and add to current session      
  13.                 AVCaptureVideoDataOutput *output = [[AVCaptureVideoDataOutput alloc] init];
  14.                 [session addOutput:output];
  15.                
  16.                 // Start session configuration
  17.                 [session beginConfiguration];
  18.                 [device lockForConfiguration:nil];
  19.                
  20.                 // Set torch to on
  21.                 [device setTorchMode:AVCaptureTorchModeOn];
  22.                
  23.                 [device unlockForConfiguration];
  24.                 [session commitConfiguration];
  25.                
  26.                 // Start the session
  27.                 [session startRunning];
  28.                
  29.                 // Keep the session around
  30.                 [self setAVSession:session];
  31.                
  32.                 [output release];
  33.         }
  34.         else
  35.         {
  36.                 [AVSession stopRunning];
  37.                 [AVSession release], AVSession = nil;
  38.         }
  39.  
  40. //objectc/7028

回复 "用代码打开IOS设备(iphone)的闪光灯"

这儿你可以回复上面这条便签

captcha