Created
October 16, 2020 03:40
-
-
Save rorodriguez116/83530652933461450f8b6ca2c4d8d8ce to your computer and use it in GitHub Desktop.
Function to check the appropriate camera permissions have been provided.
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 permisions, setup obeservers and starts running session | |
public func checkForPermissions() { | |
/* | |
Check the video authorization status. Video access is required and audio | |
access is optional. If the user denies audio access, CameraService won't | |
record audio during movie recording. | |
*/ | |
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. | |
Note that audio access will be implicitly requested when we | |
create an AVCaptureDeviceInput for audio during session setup. | |
*/ | |
sessionQueue.suspend() | |
AVCaptureDevice.requestAccess(for: .video, completionHandler: { granted in | |
if !granted { | |
self.setupResult = .notAuthorized | |
} | |
self.sessionQueue.resume() | |
}) | |
default: | |
// The user has previously denied access. | |
setupResult = .notAuthorized | |
DispatchQueue.main.async { | |
self.alertError = AlertError(title: "Camera Access", message: "SwiftCamera does not have permissions to use the camera, please update your settings", primaryButtonTitle: "Configuración", 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