Created
October 22, 2020 16:20
-
-
Save rorodriguez116/513619c91a7b228c0c8e01aa1d9453d6 to your computer and use it in GitHub Desktop.
Function to check camera access permissions.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: Checks for user's permisions | |
public func checkForPermissions() { | |
switch AVCaptureDevice.authorizationStatus(for: .video) { | |
case .authorized: | |
// The user has previously granted access to the camera. | |
break | |
case .notDetermined: | |
/* | |
The user has not yet been presented with the option to grant | |
video access. Suspend the session queue to delay session | |
setup until the access request has completed. | |
*/ | |
sessionQueue.suspend() | |
AVCaptureDevice.requestAccess(for: .video, completionHandler: { granted in | |
if !granted { | |
self.setupResult = .notAuthorized | |
} | |
self.sessionQueue.resume() | |
}) | |
default: | |
// The user has previously denied access. | |
// Store this result, create an alert error and tell the UI to show it. | |
setupResult = .notAuthorized | |
DispatchQueue.main.async { | |
self.alertError = AlertError(title: "Camera Access", message: "SwiftCamera doesn't have access to use your camera, please update your privacy settings.", primaryButtonTitle: "Settings", secondaryButtonTitle: nil, primaryAction: { | |
UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!, | |
options: [:], completionHandler: nil) | |
}, secondaryAction: nil) | |
self.shouldShowAlertView = true | |
self.isCameraUnavailable = true | |
self.isCameraButtonDisabled = true | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello! Thanks for this helpful function. Could I ask what type of queue is
self.sesionQueue
and how it's used in this context?