OGeek|极客世界-中国程序员成长平台

标题: ios - 即使相机权限被拒绝,当前的 ARFrame 也不为零 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 19:33
标题: ios - 即使相机权限被拒绝,当前的 ARFrame 也不为零

我有一个 ARKit 应用程序,我需要在其中获取当前 ARFrame 对象的 capturedImage 并将其用于进一步处理。我的代码大致是这样的:

guard let frame = sceneView.session.currentFrame else {
  return
}

someMethod(frame)

现在,我希望仅在设置 ARKit 的应用程序的前几毫秒内,或者如果此应用程序的相机权限被拒绝时,帧才会为 nil。但是,当第一次安装应用程序并且在被询问时我拒绝许可时,我会得到非零帧,其中每个像素都是黑色的。如果我再次运行应用程序,我应该得到 nil 帧。这是错误还是背后有逻辑?



Best Answer-推荐答案


我的猜测是处理权限的代码异步运行,在完成之前我们得到了一些非零帧。
所以我在 viewDidLoad 中尝试了这个:

AVCaptureDevice.requestAccess(for: .video) { (permission) in
    if !permission{
        print("not permited")
    }else{
        print("permited")
        self.scan = true
    }
}

func renderer(_ renderer: SCNSceneRenderer, updateAtTime time: TimeInterval) {
    if scan{
        guard let frame = sceneView.session.currentFrame else {
            return
        }
        //code
    }
}

只有在用户授予权限的情况下,您才能让您的代码运行。

关于ios - 即使相机权限被拒绝,当前的 ARFrame 也不为零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48104008/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4