当前位置 : 主页 > 手机开发 > 其它 >

swift – AVCaptureDevice.requestAccessForMediaType永远不会弹出窗口并始终返回false

来源:互联网 收集:自由互联 发布时间:2021-06-11
我有一些问题询问用户有关相机的许可. authorizationStatus始终是NotDetermined.当我试图询问用户是否允许时,AVCaptureDevice.requestAccessForMediaType永远不会弹出一个对话框并且被授予总是返回fals
我有一些问题询问用户有关相机的许可. authorizationStatus始终是NotDetermined.当我试图询问用户是否允许时,AVCaptureDevice.requestAccessForMediaType永远不会弹出一个对话框并且被授予总是返回false.我也找不到我的应用程序设置 – 隐私 – 相机.

任何人都可以帮助我吗?非常感谢

let availableCameraDevices = AVCaptureDevice.devicesWithMediaType(AVMediaTypeVideo)
    for device in availableCameraDevices{

        if (device.position == .Back){
            backCameraDevice = device
        }else{
            if (device.position == .Front){
                frontCameraDevice = device
            }
        }
    }

    let authorizationStatus = AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo)
    switch authorizationStatus {
    case .NotDetermined:
        // permission dialog not yet presented, request authorization
        AVCaptureDevice.requestAccessForMediaType(AVMediaTypeVideo,
            completionHandler: { (granted:Bool) -> Void in
                if (granted == false) {
                    print(granted)
                }
                else {
                    print(granted)
                }
        })
    case .Authorized: break
        // go ahead
    case .Denied, .Restricted: break
        // the user explicitly denied camera usage or is not allowed to access the camera devices
    }
问题解决了.似乎当我们从iOS 8升级到iOS 9时,它在info.plist中有一个新属性,即Bundle Display Name.如果名称为null,则将名称设置为您的产品名称,否则系统将永远不知道应用程序要求获取权限
网友评论