2014-10-10 64 views
1

的inspite在ios7, 工作正常的,但在iOS8上的火炬沾到暗的時候iOS8上的火炬轉彎時暗,下面的代碼用於禁用火炬設置AVCaptureTorchModeOff

AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; 
        if ([device hasTorch] || [device hasFlash]){ 
         [device lockForConfiguration:nil]; 
         [device setTorchMode:AVCaptureTorchModeOff]; 
         [device setFlashMode:AVCaptureFlashModeOff]; 
         [device unlockForConfiguration]; 
        } 
+0

http://stackoverflow.com/a/14740500/1106035 – 2014-10-10 14:25:09

+0

你有沒有設法關閉它在iOS的8 – Burf2000 2015-01-06 13:42:47

回答

2

試試這個代碼,它的工作原理...

- (IBAction)flashOnClicked:(id)sender 
    { 
     AVCaptureDevice *flashLight = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; 
     if ([flashLight isTorchAvailable] && [flashLight isTorchModeSupported:AVCaptureTorchModeOn]) 
     { 
      BOOL success = [flashLight lockForConfiguration:nil]; 
      if (success) 
      { 
       if ([flashLight isTorchActive]) 
       { 
        //TURN ON 
        [flashLight setTorchMode:AVCaptureTorchModeOff]; 
       } 
       else 
       { 
        //TURN OFF 
        [flashLight setTorchMode:AVCaptureTorchModeOn]; 
       } 
       [flashLight unlockForConfiguration]; 
      } 
     } 
    } 
+0

不靈其進入成功狀態,但仍是光沾到 – 2014-10-16 08:40:37