Skip to content

Commit

Permalink
Enable Torch Mode
Browse files Browse the repository at this point in the history
  • Loading branch information
retendo committed Mar 5, 2021
1 parent dfd2c61 commit ac72019
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Sources/BarcodeHeroUI/Controllers/BHCameraScanController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,29 @@
}
}

public enum FlashStatus {
case off, on, unavailable
}
public func getFlashStatus() -> FlashStatus {
guard let avDevice = AVCaptureDevice.default(for: .video), avDevice.hasTorch, avDevice.isTorchAvailable else { return .unavailable }
return avDevice.isTorchActive ? .on : .off
}
public func toggleFlashStatus() -> FlashStatus {
guard let avDevice = AVCaptureDevice.default(for: .video), avDevice.hasTorch, avDevice.isTorchAvailable, (try? avDevice.lockForConfiguration()) != nil else {
AVCaptureDevice.default(for: .video)?.unlockForConfiguration()
return .unavailable
}
defer { avDevice.unlockForConfiguration() }

if avDevice.isTorchActive {
avDevice.torchMode = AVCaptureDevice.TorchMode.off
return .off
} else {
avDevice.torchMode = AVCaptureDevice.TorchMode.on
return .on
}
}

public func evolve(withText text: String) {
if isEvolving { return }
isEvolving = true
Expand Down

0 comments on commit ac72019

Please sign in to comment.