我有一些问题要求用户关于相机的权限。 authorizationStatus
总是NotDetermined
。当我试图询问用户许可时,AVCaptureDevice.requestAccessForMediaType
永远不会弹出对话框,并始终返回false
。我也无法在设置 - 隐私 - 相机中找到我的应用程序。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
}
我试图构建一个新的应用程序并运行相同的代码,并且它会触发系统对话框以允许允许。但是,它不适用于我的旧应用程序...我不确定是否有任何需要在info.list中设置的内容。此外,我已经尝试重置隐私多次,并且我的iPhone上的每个应用程序都请求访问除我的摄像头外的其他设备。 –
更新:在新应用程序中,当我运行AVCaptureDevice.requestAccessForMediaType时,它首先弹出一个系统对话框让用户选择,然后返回授予。但在我的应用程序,AVCaptureDevice.requestAccessForMediaType只是自动拒绝权限 –
即使重置?也许你的应用程序对UIKit做一些有趣的事 –