Skip to content
All gists
Back to GitHub
Sign in
Sign up
Sign in
Sign up
{{ message }}
Instantly share code, notes, and snippets.
hashaam
/
request-camera-authorization-controller.swift
Last active
Aug 16, 2020
Star
0
Fork
0
Star
Code
Revisions
3
Embed
What would you like to do?
Embed
Embed this gist in your website.
Share
Copy sharable link for this gist.
Clone via HTTPS
Clone with Git or checkout with SVN using the repository’s web address.
Learn more about clone URLs
Download ZIP
Raw
request-camera-authorization-controller.swift
//
Youtube: https://www.youtube.com/watch?v=7AlZxClmhPw
//
Source: https://hashaam.com/2020/07/30/creating-camera-application-with-avfoundation/
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
{
completionHandler
(.
unauthorized
)
return
}
completionHandler
(.
granted
)
}
})
}
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
You can’t perform that action at this time.
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.