小智 8
func toggleTorch(on: Bool) {
guard let device = AVCaptureDevice.default(for: AVMediaType.video)
else {return}
if device.hasTorch {
do {
try device.lockForConfiguration()
if on == true {
device.torchMode = .on // set on
} else {
device.torchMode = .off // set off
}
device.unlockForConfiguration()
} catch {
print("Torch could not be used")
}
} else {
print("Torch is not available")
}
}
Run Code Online (Sandbox Code Playgroud)
称之为
toggleTorch(on:false)的toggleTorch(on:true)
ref:用Swift攻击
| 归档时间: |
|
| 查看次数: |
995 次 |
| 最近记录: |