-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is needed
Milestone
Description
Overview
Let's add a way to control the torch on the device.
This could go under a new namespace Control.Flashlight π‘
Tactics
Thanks ChatGPT π€
Check flashlight availability
import AVFoundation
if let device = AVCaptureDevice.default(for: .video), device.hasTorch {
print("Torch is available")
} else {
print("Torch is not available")
}Turn the Flashlight on or off
func toggleFlashlight(on: Bool) {
guard let device = AVCaptureDevice.default(for: .video), device.hasTorch else {
print("Torch is not available")
return
}
do {
try device.lockForConfiguration()
if on {
try device.setTorchModeOn(level: AVCaptureDevice.maxAvailableTorchLevel)
} else {
device.torchMode = .off
}
device.unlockForConfiguration()
} catch {
print("Error accessing the torch: \(error.localizedDescription)")
}
}Testing
- Unit tests? π§ͺπ§ͺ
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is needed