How do I use AVCaptureFlashMode

后端 未结 1 472
醉梦人生
醉梦人生 2021-02-06 16:51

I\'m making an app to allow me to stitch images together into a panoramic scene. I want to be able to turn the Flash LED on the iPhone 4 programatically.

How can I do th

相关标签:
1条回答
  • 2021-02-06 17:22
    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];
    }
    
    0 讨论(0)
提交回复
热议问题