Difference between revisions of "AVFlashlight"

From iPhone Development Wiki
Jump to: navigation, search
(Example usage: It should be there.)
(Fix code)
Line 25: Line 25:
  
 
// Make sure you don't have any others AVFlashlight object instantiated
 
// Make sure you don't have any others AVFlashlight object instantiated
flashlight = [[AVFlashlight alloc] init];
+
if ([AVFlashlight hasFlashlight]) {
if ([flashlight hasFlashlight])
+
  flashlight = [[AVFlashlight alloc] init];
 
   [flashlight setFlashlightLevel:AVCaptureMaxAvailableTorchLevel withError:nil];
 
   [flashlight setFlashlightLevel:AVCaptureMaxAvailableTorchLevel withError:nil];
 +
}
  
 
...
 
...

Revision as of 00:43, 20 June 2014

AVFlashlight is a private class introduced in iOS 7 for turning the device's LED flash on or off. The example application that uses this class is Control Center in SpringBoard.

Methods

Signature +(BOOL)hasFlashlight;
Available in 7.0 —

The method +[AVFlashlight hasFlashlight] indicates the LED flash availability.

Signature -(BOOL)setFlashlightLevel:(float)level withError:(NSError *)error;
Available in 7.0 —

The method -[AVFlashlight setFlashlightLevel:withError:] is used for setting the flashlight level.

Example usage

AVFlashlight *flashlight;

...

// Make sure you don't have any others AVFlashlight object instantiated
if ([AVFlashlight hasFlashlight]) {
   flashlight = [[AVFlashlight alloc] init];
   [flashlight setFlashlightLevel:AVCaptureMaxAvailableTorchLevel withError:nil];
}

...

// Do this when you want to turn power/light off the LED flash
[flashlight release];