【问题标题】:Popup is not coming to ask permission to access camera in iOS 12弹出窗口不会在 iOS 12 中请求访问相机的权限
【发布时间】:2018-10-03 07:58:31
【问题描述】:

根据苹果标准,我们需要获得访问用户摄像头的权限。所以我已经成功集成了摄像头,它在 iOS 11 中运行良好。但目前,我正在测试摄像头功能,发现如果用户曾经允许摄像头访问,即使在全新安装后,同一个应用程序也不会请求许可(来自应用商店)。

所以我的问题是,iOS 12 中的行为是否发生了变化,或者我们需要进行一些设置以在每次用户尝试安装新应用时询问权限?

谢谢

【问题讨论】:

  • @Scriptable,不幸的是它看起来很相似。
  • 我在 iOS 12 上遇到了同样的问题,你解决了吗?
  • @CGR,我认为在 iOS 12 中,Apple 改变了行为。如果您立即授予许可,他们不会在全新安装后第二次请求许可。它将存储在操作系统级别,可能带有捆绑标识符。
  • @JatinPatel 是的,我也面临同样的问题,我的应用由于访问隐私敏感数据而被拒绝,他们说我没有在 plist 中包含 NSCameraUsageDescription。但它在项目中,并没有弹出默认权限警报。

标签: ios ios12


【解决方案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)
}

【讨论】:

  • 对我来说,我的应用设置中没有相机选项
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-24
  • 2012-11-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-24
相关资源
最近更新 更多