(Fix code) |
m (→Example usage) |
||
Line 20: | Line 20: | ||
<source lang=objc> | <source lang=objc> | ||
AVFlashlight *flashlight; | static AVFlashlight *flashlight; | ||
... | ... | ||
// Make sure you don't have any | // Make sure you don't have any other AVFlashlight object instantiated | ||
if ([AVFlashlight hasFlashlight]) { | if ([AVFlashlight hasFlashlight]) { | ||
flashlight = [AVFlashlight new]; | |||
[flashlight setFlashlightLevel:AVCaptureMaxAvailableTorchLevel withError:nil]; | |||
} | } | ||
Line 33: | Line 33: | ||
// Do this when you want to turn power/light off the LED flash | // Do this when you want to turn power/light off the LED flash | ||
[flashlight | [flashlight turnPowerOff]; | ||
</source> | </source> | ||
{{occlass|library=AVFoundation.framework|navbox=1}} | {{occlass|library=AVFoundation.framework|navbox=1}} |
Revision as of 02:44, 25 October 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
static AVFlashlight *flashlight;
...
// Make sure you don't have any other AVFlashlight object instantiated
if ([AVFlashlight hasFlashlight]) {
flashlight = [AVFlashlight new];
[flashlight setFlashlightLevel:AVCaptureMaxAvailableTorchLevel withError:nil];
}
...
// Do this when you want to turn power/light off the LED flash
[flashlight turnPowerOff];
|