【问题标题】:UIImagePickerController isSourceTypeAvailable(type) always trueUIImagePickerController isSourceTypeAvailable(type) 始终为真
【发布时间】:2020-04-30 23:00:37
【问题描述】:

如果我通过设置应用程序阻止摄像头,此函数始终返回 true。它完全忽略了权限。其他人注意到了吗?

【问题讨论】:

    标签: ios permissions camera


    【解决方案1】:

    使用AVCaptureDevice.authorizationStatus(for: cameraMediaType) 进行授权检查

    func checkCameraAuth() {
            let authorizationStatus = AVCaptureDevice.authorizationStatus(for: .video)
            switch authorizationStatus{
            case .denied:
                print("you can request permission from settings")
    
            case .restricted:
                print("Restricted")
            case .authorized:
                print("Authorized, proceed")
            case .notDetermined:
                AVCaptureDevice.requestAccess(for: .video) { success in
                    if success {
                        print("Permission granted you can now perform operation here")
                    } else {
                        print("Permission denied")
                    }
                }
            @unknown default:
                fatalError()
            }
        }
    

    【讨论】:

    • 您应该扩展您的答案,以帮助搜索此问题的其他人更好地了解如何解决该问题。
    • 你说得对,我认为这家伙已经掌握了一些强大的技能,因为他捕捉到了一个场景。但你是对的,应该提供细节让我更新答案:)
    【解决方案2】:

    在 swift 4 中,您可以通过这种方式检查您的相机是否可用:

    if AVCaptureDevice.authorizationStatus(for: .video) ==  .authorized {
        //already authorized
    } else {
        AVCaptureDevice.requestAccess(for: .video, completionHandler: { (granted: Bool) in
            if granted {
                //access allowed
            } else {
                //access denied
            }
        })
    }
    

    从这里的答案 -> How to check if the user gave permission to use the camera?

    【讨论】:

      猜你喜欢
      • 2016-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-23
      • 2015-12-05
      • 2019-02-01
      • 2021-01-07
      • 2014-07-17
      相关资源
      最近更新 更多