I'd like to add flashlight functionality to my app in Swift. How can I go about doing that?
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- SwiftUI: UIImage (QRCode) does not load after call
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Using if let syntax in switch statement
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Enum with associated value conforming to CaseItera
- Swift - hide pickerView after value selected
- Is there a Github markdown language identifier for
Like so:
For xcode 9.1, swift 4 (updated to not crash if no torch):
For swift 3
Updated Swift 4 Answer:
Then to actually turn it on or off, call the function and pass in a true or false boolean.
toggleTorch(on: true)
oftoggleTorch(on: false)
I got this answer from Hacking with Swift, however their example had an error in it.
They used
AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeVideo)
but this produces an error sayingdefaultDevice
doesn't exist. So I changed it toAVCaptureDevice.default(for: AVMediaType.video)
Swift 4.2