Skip to content

Instantly share code, notes, and snippets.

@b-r-o
Created January 2, 2017 23:07
Show Gist options
  • Save b-r-o/8d3f298d5bd224a4407088453706f1ac to your computer and use it in GitHub Desktop.
Save b-r-o/8d3f298d5bd224a4407088453706f1ac to your computer and use it in GitHub Desktop.
Clean permission request mechanism
init() {
checkPermission()
sessionQueue.async { [unowned self] in
self.configureSession()
self.captureSession.startRunning()
}
}
// MARK: AVSession configuration
private func checkPermission() {
switch AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeVideo) {
case .authorized:
permissionGranted = true
case .notDetermined:
requestPermission()
default:
permissionGranted = false
}
}
private func requestPermission() {
sessionQueue.suspend()
AVCaptureDevice.requestAccess(forMediaType: AVMediaTypeVideo) { [unowned self] granted in
self.permissionGranted = granted
self.sessionQueue.resume()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment