iOS 12中未弹出要求访问相机的权限窗口

6
根据苹果标准,我们需要请求许可才能访问用户摄像头。因此,我已经成功地集成了相机,并且在iOS 11中运行良好。但是目前我正在测试相机功能,发现如果用户允许一次相机访问,则在重新安装(从应用商店)后,同一应用程序将不会再次请求许可。
所以我的问题是,iOS 12的行为是否已更改,或者我们需要进行某些设置,以便每次用户尝试安装新应用时都要求请求许可?
谢谢。

相关问题:https://stackoverflow.com/questions/52622481/ios-12-camera-working-without-camera-permission-dialog-box - Scriptable
@Scriptable,不幸的是,这看起来是一个类似的问题。 - Jatin Patel - JP
我在iOS 12上也遇到了同样的问题,你解决了吗? - CGR
@Vikky,还没有解决。尽管苹果会批准我的应用程序。 - Jatin Patel - JP
@JatinPatel 你找到解决方案了吗?我在iOS 12.1上仍然有同样的错误。 - Zgpeace
显示剩余5条评论
1个回答

1

iOS 12.1 / Swift 4.2

每当用户在您的应用程序中点击相机按钮时,您将调用此代码。首先它会请求权限,如果设置仍然存在于过去的安装中,则UIAlertController会弹出,允许用户打开设备上的“设置”应用程序并更改相机权限设置。

OnCameraOpenButtonTap()

if UIImagePickerController.isSourceTypeAvailable(.camera) {
   checkCameraAccess(isAllowed: {
            if $0 {
                DispatchQueue.main.async {
                    self.presentCamera()
                }
            } else {
                DispatchQueue.main.async {
                self.presentCameraSettings()
            }
        }
    })
}

func checkCameraAccess(isAllowed: @escaping (Bool) -> Void) {
    switch AVCaptureDevice.authorizationStatus(for: .video) {
    case .denied:
        isAllowed(false)
    case .restricted:
        isAllowed(false)
    case .authorized:
        isAllowed(true)
    case .notDetermined:
        AVCaptureDevice.requestAccess(for: .video) { isAllowed($0) }
    }
}

private func presentCamera() {
    let imagePicker = UIImagePickerController()
    imagePicker.delegate = self
    imagePicker.sourceType = .camera
    present(imagePicker, animated: true, completion: nil)
}

private func presentCameraSettings() {
    let alert = UIAlertController.init(title: "allowCameraTitle", message: "allowCameraMessage", preferredStyle: .alert)
    alert.addAction(UIAlertAction.init(title: "Cancel", style: .cancel, handler: { (_) in
    }))

    alert.addAction(UIAlertAction.init(title: "Settings", style: .default, handler: { (_) in
        UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!, options: [:], completionHandler: nil)
    }))

    present(alert, animated: true)
}

1
对我来说,相机选项不在我的应用程序设置中。 - krishan kumar

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接