相机和照片库权限 - 当用户不接受允许时处理 iOS 10

Camera & Photo Library Permission - Handle when a user does not accept to allow iOS 10

我请求用户同意访问照片库和使用相机。我希望能够处理用户不接受的情况,但我在这样做时遇到了问题。这是我检查用户权限时的代码:

AVCaptureDevice.requestAccess(forMediaType: AVMediaTypeVideo) { granted in
        if granted {
            if(!self.captureSession.isRunning){
                self.setupCustomCamera()
            }
        } else {
            self.takePhotoButton.alpha = 0.5
            self.takePhotoButton.isEnabled = false
            self.showNeedAccessMessage()
        }
}

而我的showNeedAccessMessage()如下:

func showNeedAccessMessage() {
        let alert = UIAlertController(title: "Camera Settings", message: "Please adjust your device settings to grant access to camera use.", preferredStyle: .alert)

        alert.addAction(UIAlertAction(title: "OK", style: .cancel, handler: { (action: UIAlertAction) -> Void in
            self.dismiss(animated: true, completion: nil)
        }))

        show(alert, sender: nil)
}

这里的问题是,当 granted 的情况不符合时,我想显示一个警报。我的应用程序没有显示警报,而是尝试打开 'Image Settings' 页面,显示如下:

这种情况有默认处理吗?如果是这样,我将如何修复黑色 'Image Settings' 屏幕有什么想法吗?

提前致谢!

 AVCaptureDevice.requestAccess(forMediaType: AVMediaTypeVideo, completionHandler: { (granted :Bool) -> Void in
                if granted == true
                {
                    // User granted
                }
                else
                {
                    let alert = UIAlertController(title: "Error", message: "This app is not authorized to use Camera.", preferredStyle: .alert)

                    alert.addAction(UIAlertAction(title: "Setting", style: .default, handler: { (_) in
                        DispatchQueue.main.async {
                            if let settingsURL = URL(string: UIApplicationOpenSettingsURLString) {
                                UIApplication.shared.openURL(settingsURL)
                            }
                        }
                    }))
                    alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
                    self.present(alert, animated: true, completion: nil)

                    return
                }
            });