Difference between revisions of "AVFlashlight"

From iPhone Development Wiki
Jump to: navigation, search
m (It's actually CGFloat.)
m (Updated.)
 
Line 8: Line 8:
 
}}
 
}}
  
The method {{ObjcCall|AVFlashlight|hasFlashlight|ClassMethod=1}} indicates the LED flash availability.
+
The method {{ObjcCall|AVFlashlight|hasFlashlight|ClassMethod=1}} indicates the LED flash availability. It is equivalent to <code>MGGetBoolAnswer(CFSTR("camera-flash"))</code>
  
 
{{function signature
 
{{function signature
Line 27: Line 27:
 
if ([AVFlashlight hasFlashlight]) {
 
if ([AVFlashlight hasFlashlight]) {
 
flashlight = [AVFlashlight new];
 
flashlight = [AVFlashlight new];
[flashlight setFlashlightLevel:1.0f withError:nil];
+
[flashlight setFlashlightLevel:1.0 withError:nil];
 
}
 
}
  

Latest revision as of 06:00, 4 August 2017

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. It is equivalent to MGGetBoolAnswer(CFSTR("camera-flash"))

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

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

Example usage

static AVFlashlight *flashlight;

...

// Make sure you don't have any other AVFlashlight object instantiated, or this flashlight won't be functional.
if ([AVFlashlight hasFlashlight]) {
	flashlight = [AVFlashlight new];
	[flashlight setFlashlightLevel:1.0 withError:nil];
}

...

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