弹出窗口不会要求在iOS 12中访问相机的权限 [英] Popup is not coming to ask permission to access camera in iOS 12

查看:307
本文介绍了弹出窗口不会要求在iOS 12中访问相机的权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据Apple标准,我们需要征得访问用户相机的许可.因此我已经成功集成了摄像头,并且它在iOS 11中可以正常工作.但是目前,我正在测试摄像头功能,并发现如果用户一次允许摄像头访问,即使重新安装后该同一个应用也不会请求许可(从应用商店).

As per the apple standard, we need to ask permission to access user camera. so I have successfully integrated camera and it is working fine in iOS 11. but currently, I am testing camera feature and found that if user one time allowed camera access, The same app will not ask for permission even after fresh installed(from app store).

所以我的问题是,它是否在iOS 12中发生了变化,还是每次用户尝试安装全新的App时都需要进行一些设置以获取许可?

so my question is, is it behavious changed in iOS 12 or we need to do some setup to asked permission every time when user try to install fresh App?

谢谢

推荐答案

iOS 12.1/Swift 4.2

每次用户点击应用程序中的相机"按钮时,都会调用此代码.首先,它会询问权限,如果以前的安装中的设置仍然存在,则会弹出UIAlertController,允许用户打开设备上的设置"应用程序,并更改摄像头的权限设置.

Every time the user taps on the Camera button in your app, you call this code. It firstly asks for permissions, and if the settings are still there from the past installs, UIAlertController pops up, allowing the user to open the Settings app on the device, and change camera permission settings.

OnCameraOpenButtonTap()

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)
}

这篇关于弹出窗口不会要求在iOS 12中访问相机的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆