拒绝相机后访问相机问题

时间:2017-04-19 05:29:42

标签: ios swift camera native

在我的应用程序中,我使用了相机实现,如果用户输入第一个意味着他们选择允许的时间意味着他们必须在整个应用程序中访问相机和照片库,如果选择被拒绝则意味着用户无法访问相机那个时候我们需要在设置中更改相机和照片库。之后我们必须在我的情况下访问相机它不能正常工作,任何人都帮助我,非常感谢。

1 个答案:

答案 0 :(得分:3)

您可以先检查是否允许相机许可。如果没有,那么您可以导航到设置屏幕&请用户许可。

 override func viewDidLoad() {
        super.viewDidLoad()
        checkCameraPermission()
    }
    func checkCameraPermission()  {
        let cameraMediaType = AVMediaTypeVideo
        AVCaptureDevice.requestAccess(forMediaType: cameraMediaType) { granted in
            if granted {
                //Do operation
                print("Granted access for camera")
                self.setCamera()
            } else {
                self.noCameraFound()
                print("Denied access for camera ")
            }
        }
    }
    func noCameraFound(){
        let alert = UIAlertController(title: "AppName", message: "Please allow camera access in phone settings", preferredStyle: UIAlertControllerStyle.alert)
        alert.addAction(UIAlertAction(title: "Back", style: UIAlertActionStyle.cancel, handler: {(action:UIAlertAction) in


        }));

        alert.addAction(UIAlertAction(title: "Open setting ", style: UIAlertActionStyle.default, handler: {(action:UIAlertAction) in
            UIApplication.shared.open(NSURL(string:UIApplicationOpenSettingsURLString)! as URL, options: [:], completionHandler: nil)

        }));
        self.present(alert, animated: true, completion: nil)
    }
相关问题