Reputation: 161
I have some problem asking user for permission about camera. The authorizationStatus
is always NotDetermined
. When I tried to ask user for permission, AVCaptureDevice.requestAccessForMediaType
never pops up a dialog and granted always returns false
. I also can't find my app in settings - privacy - camera.
Can anyone help me with that? really appreciated
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
}
Upvotes: 7
Views: 4570
Reputation: 6070
This happens to me after disabling the macOS SIP in recovery mode, enabling it back and all the authorize dialogs show up.
Upvotes: 0
Reputation: 885
If it's taking a long time to appear, then it sounds like you're not running this on the main thread, which you should be. Also, if it has prompted once before, it won't prompt again – the user has to go into Settings and enable camera access.
from ALex requestAccessForMediaType doesn't ask for permission
Upvotes: 1
Reputation: 161
Problem solved. It seems that when we upgrade from iOS 8 to iOS 9, it has a new property in info.plist which is Bundle Display Name. Set the name to your product name if it is null, or the system will never know what app is asking for a permission
Upvotes: 9
Reputation: 36074
You should always be able to present the permission dialog when authorization status is .NotDetermined
.
This and the fact that you can't find the app in privacy settings makes it sound like your phone is confused - so try resetting your privacy settings by going to Settings.app > General > Reset
and hitting Reset Location & Privacy
.
Upvotes: 0