Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
// Youtube:
// Source:
import Foundation
import AVFoundation
enum CameraAuthorizationStatus {
case notRequested
case granted
case unauthorized
typealias RequestCameraAuthorizationCompletionHandler = (CameraAuthorizationStatus) -> Void
class RequestCameraAuthorizationController {
static func requestCameraAuthorization(completionHandler: @escaping RequestCameraAuthorizationCompletionHandler) {
AVCaptureDevice.requestAccess(for: .video, completionHandler: { granted in
DispatchQueue.main.async {
guard granted else {
static func getCameraAuthorizationStatus() -> CameraAuthorizationStatus {
let status = AVCaptureDevice.authorizationStatus(for: .video)
switch status {
case .authorized: return .granted
case .notDetermined: return .notRequested
default: return .unauthorized
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment