From 9a8b8cd3f22bb5a4dd3a0595eba573990be4c8f7 Mon Sep 17 00:00:00 2001 From: Kristijan Perusko Date: Wed, 23 Dec 2015 16:55:47 -0500 Subject: [PATCH] Hotfix for asking permissions when opening the Camera dialog --- .../Views/TimerViewController.swift | 40 ++++++++++++++----- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/DesignStudioExpress/Views/TimerViewController.swift b/DesignStudioExpress/Views/TimerViewController.swift index 19a77c0..29e2b13 100644 --- a/DesignStudioExpress/Views/TimerViewController.swift +++ b/DesignStudioExpress/Views/TimerViewController.swift @@ -76,21 +76,18 @@ class TimerViewController: UIViewControllerBase, MZTimerLabelDelegate { } @IBAction func takePicture(sender: AnyObject) { - if AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo) == .Authorized { + let authorizationStatus = AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo) + + switch authorizationStatus { + case .Authorized: self.showCamera() - } else { - self.showWarningAlert(self.cameraAccessErrorTitle, message: self.cameraAccessErrorMessage) + case .NotDetermined: + self.requestAccess() + default: + self.showWarningAlert() } } - private func showWarningAlert(title: String, message: String) { - let alertController = UIAlertController(title: title, message: message, preferredStyle: .Alert) - let okAction = UIAlertAction(title: "OK", style: .Default, handler: nil) - alertController.addAction(okAction) - - self.presentViewController(alertController, animated: true, completion: nil) - } - private func showCamera() { let camera = DKCamera() @@ -107,6 +104,27 @@ class TimerViewController: UIViewControllerBase, MZTimerLabelDelegate { self.presentViewController(camera, animated: true, completion: nil) } + private func requestAccess() { + AVCaptureDevice.requestAccessForMediaType(AVMediaTypeVideo) { (granted: Bool) -> Void in + if granted { + self.showCamera() + } else { + self.showWarningAlert() + } + } + } + + private func showWarningAlert() { + let title = self.cameraAccessErrorTitle + let message = self.cameraAccessErrorMessage + let alertController = UIAlertController(title: title, message: message, preferredStyle: .Alert) + let okAction = UIAlertAction(title: "OK", style: .Default, handler: nil) + alertController.addAction(okAction) + + self.presentViewController(alertController, animated: true, completion: nil) + } + + // MARK: StyledNavigationBar override func customizeNavBarStyle() {