Skip to content

Commit

Permalink
Hotfix for asking permissions when opening the Camera dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
kperusko committed Dec 23, 2015
1 parent 3822e93 commit 9a8b8cd
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions DesignStudioExpress/Views/TimerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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() {
Expand Down

0 comments on commit 9a8b8cd

Please sign in to comment.