首页 > 解决方案 > 再次请求访问相机时如何恢复默认状态(状态==。未确定)

问题描述

我正在开发一个具有录音功能的应用程序。
我知道当用户第一次被要求访问请求时,授权状态是不确定的。一旦用户被要求访问相机(这是用户选择是否授权或拒绝的时候),授权状态将无法恢复到默认状态(状态 == .notDetermined)。

为了测试,有没有办法获得默认状态(status == .notDetermined)?

switch AVCaptureDevice.authorizationStatus(for: .video) {
case .authorized: // The user has previously granted access to the camera.
    self.setupCaptureSession()

case .notDetermined: 
// The user has not yet been asked for camera access.
// Once the user has been asked for camera access, this will never be executed again. 
    AVCaptureDevice.requestAccess(for: .video) { granted in
        if granted {
            self.setupCaptureSession()
        }
    }

case .denied: // The user has previously denied access.
    return

case .restricted: // The user can't grant access due to restrictions.
    return
}

标签: iosswift

解决方案


卸载已经存在的应用程序并尝试在一天后重新安装新版本以.notDetermined获得AVCaptureDevice.authorizationStatus. 您无法以编程方式重置权限。您也可以通过重置设备来重置权限,这似乎有点苛刻。总之,有两种方法可以做到这一点:

  1. 重置操作系统
  2. 卸载应用程序并等待一天

推荐阅读