From 85d9bc917c03e762c78f4dffc505e1f142489fba Mon Sep 17 00:00:00 2001 From: Andrew Walz Date: Wed, 30 Aug 2017 21:17:54 -0600 Subject: [PATCH] Added delegate for failed configuration --- .../DemoSwiftyCam/ViewController.swift | 10 ++++++++++ Source/SwiftyCamViewController.swift | 17 +++++++---------- Source/SwiftyCamViewControllerDelegate.swift | 13 +++++++++++++ 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/DemoSwiftyCam/DemoSwiftyCam/ViewController.swift b/DemoSwiftyCam/DemoSwiftyCam/ViewController.swift index 8d3e90f..17c6a5c 100644 --- a/DemoSwiftyCam/DemoSwiftyCam/ViewController.swift +++ b/DemoSwiftyCam/DemoSwiftyCam/ViewController.swift @@ -87,12 +87,22 @@ class ViewController: SwiftyCamViewController, SwiftyCamViewControllerDelegate { }) }) } + + func swiftyCamDidFailToConfigure(_ swiftyCam: SwiftyCamViewController) { + let message = NSLocalizedString("Unable to capture media", comment: "Alert message when something goes wrong during capture session configuration") + let alertController = UIAlertController(title: "AVCam", message: message, preferredStyle: .alert) + alertController.addAction(UIAlertAction(title: NSLocalizedString("OK", comment: "Alert OK button"), style: .cancel, handler: nil)) + present(alertController, animated: true, completion: nil) + } func swiftyCam(_ swiftyCam: SwiftyCamViewController, didChangeZoomLevel zoom: CGFloat) { + print("Zoom level did change. Level: \(zoom)") print(zoom) } func swiftyCam(_ swiftyCam: SwiftyCamViewController, didSwitchCameras camera: SwiftyCamViewController.CameraSelection) { + print("Camera did change to \(camera.rawValue)") + print(camera) } diff --git a/Source/SwiftyCamViewController.swift b/Source/SwiftyCamViewController.swift index 2a86dff..332e0c4 100644 --- a/Source/SwiftyCamViewController.swift +++ b/Source/SwiftyCamViewController.swift @@ -27,13 +27,13 @@ open class SwiftyCamViewController: UIViewController { /// Enumeration for Camera Selection - public enum CameraSelection { + public enum CameraSelection: String { /// Camera on the back of the device - case rear + case rear = "rear" /// Camera on the front of the device - case front + case front = "front" } /// Enumeration for video quality of the capture session. Corresponds to a AVCaptureSessionPreset @@ -271,7 +271,7 @@ open class SwiftyCamViewController: UIViewController { // Test authorization status for Camera and Micophone - switch AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeVideo){ + switch AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeVideo) { case .authorized: // already authorized @@ -390,12 +390,9 @@ open class SwiftyCamViewController: UIViewController { self.promptToAppSettings() case .configurationFailed: // Unknown Error - DispatchQueue.main.async(execute: { [unowned self] in - let message = NSLocalizedString("Unable to capture media", comment: "Alert message when something goes wrong during capture session configuration") - let alertController = UIAlertController(title: "AVCam", message: message, preferredStyle: .alert) - alertController.addAction(UIAlertAction(title: NSLocalizedString("OK", comment: "Alert OK button"), style: .cancel, handler: nil)) - self.present(alertController, animated: true, completion: nil) - }) + DispatchQueue.main.async { + self.cameraDelegate?.swiftyCamDidFailToConfigure(self) + } } } } diff --git a/Source/SwiftyCamViewControllerDelegate.swift b/Source/SwiftyCamViewControllerDelegate.swift index 8102f06..764b2c7 100644 --- a/Source/SwiftyCamViewControllerDelegate.swift +++ b/Source/SwiftyCamViewControllerDelegate.swift @@ -15,6 +15,7 @@ import UIKit +import AVFoundation // MARK: Public Protocol Declaration @@ -95,6 +96,14 @@ public protocol SwiftyCamViewControllerDelegate: class { */ func swiftyCam(_ swiftyCam: SwiftyCamViewController, didChangeZoomLevel zoom: CGFloat) + + /** + SwiftyCamViewControllerDelegate function called when when SwiftyCamViewController fails to confiture the session. + + - Parameter swiftyCam: Current SwiftyCamViewController + */ + + func swiftyCamDidFailToConfigure(_ swiftyCam: SwiftyCamViewController) } public extension SwiftyCamViewControllerDelegate { @@ -135,6 +144,10 @@ public extension SwiftyCamViewControllerDelegate { func swiftyCam(_ swiftyCam: SwiftyCamViewController, didChangeZoomLevel zoom: CGFloat) { // Optional } + + func swiftyCamDidFailToConfigure(_ swiftyCam: SwiftyCamViewController) { + // Optional + } }