If I block the camera via the settings App, this function always returns true. It completely ignores permissions. Anybody else noticed this?
Asked
Active
Viewed 204 times
2 Answers
1
use AVCaptureDevice.authorizationStatus(for: cameraMediaType)
for authorization check
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()
}
}

Muhammad Afzal
- 201
- 1
- 9
-
1You should expand your answer to help other people who have searched for this issue to better understand how to address the problem. – Bob Dalgleish Jan 14 '20 at 19:35
-
you are right i considered the guy already have some strong skills because he capture a scenario. but you are right should provide detail let me update answer :) – Muhammad Afzal Jan 15 '20 at 05:43
0
In swift 4 you can check if your camera is available this way:
if AVCaptureDevice.authorizationStatus(for: .video) == .authorized {
//already authorized
} else {
AVCaptureDevice.requestAccess(for: .video, completionHandler: { (granted: Bool) in
if granted {
//access allowed
} else {
//access denied
}
})
}
from this answer here -> How to check if the user gave permission to use the camera?

Giuseppe Garassino
- 2,272
- 1
- 27
- 47