ios – 当火炬打开时,AVCaptureSession冻结

ios – 当火炬打开时,AVCaptureSession冻结,第1张

概述我们的iOS应用程序具有条形码扫描功能,我们可以让客户根据需要打开和关闭手电筒.在AvcaptureSession运行且手电筒启用时,在iPhone X上(仅在iPhone X上),屏幕上的视频捕获会冻结.只要再次关闭手电筒,视频捕捉就会再次开始.有没有人碰到这个?我似乎无法找到任何指向解决方案的东西.想知道这是否是iPhone X的错误? 我遇到了这个问题.经过一些实验,结果表明获得配置火炬的设 我们的iOS应用程序具有条形码扫描功能,我们可以让客户根据需要打开和关闭手电筒.在AvcaptureSession运行且手电筒启用时,在iPhone X上(仅在iPhone X上),屏幕上的视频捕获会冻结.只要再次关闭手电筒,视频捕捉就会再次开始.有没有人碰到这个?我似乎无法找到任何指向解决方案的东西.想知道这是否是iPhone X的错误?@H_301_8@解决方法 我遇到了这个问题.经过一些实验,结果表明获得配置火炬的设备必须以与配置AVCaptureSession时获得设备完全相同的方式完成.例如.:

@H_404_15@let captureSession = AVCaptureSession() let devicediscoverySession = AVCaptureDevice.discoverySession(deviceTypes: [.builtInDualCamera],mediaType: AVMediaType.vIDeo,position: .back) guard let captureDevice = devicediscoverySession.devices.first else { print("Couldn't get a camera") return } do { let input = try AVCaptureDeviceinput(device: captureDevice) captureSession!.addinput(input) } catch { print(error) return }

打开和关闭割炬(手电筒)时,使用该精确方法获取设备.在这种情况下,行:

@H_404_15@let devicediscoverySession = AVCaptureDevice.discoverySession(deviceTypes: [.builtInDualCamera],position: .back)guard let device = devicediscoverySession.devices.first

例:

@H_404_15@func toggletorch() { let devicediscoverySession = AVCaptureDevice.discoverySession(deviceTypes: [.builtInDualCamera],position: .back) guard let device = devicediscoverySession.devices.first else {return} if device.hasTorch { do { try device.lockForConfiguration() let on = device.isTorchActive if on != true && device.isTorchModeSupported(.on) { try device.setTorchModeOn(level: 1.0) } else if device.isTorchModeSupported(.off){ device.torchMode = .off } else { print("Torch mode is not supported") } device.unlockForConfiguration() } catch { print("Torch Could not be used") } } else { print("Torch is not available") }}

我意识到toggletorch函数中的某些代码可能是多余的,但我要离开它了.希望这可以帮助.

总结

以上是内存溢出为你收集整理的ios – 当火炬打开时,AVCaptureSession冻结全部内容,希望文章能够帮你解决ios – 当火炬打开时,AVCaptureSession冻结所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1033415.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-24
下一篇2022-05-24

发表评论

登录后才能评论

评论列表(0条)

    保存