Added delegate for failed configuration

This commit is contained in:
Andrew Walz 2017-08-30 21:17:54 -06:00
parent 2f4784ae39
commit 85d9bc917c
3 changed files with 30 additions and 10 deletions

View file

@ -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) { func swiftyCam(_ swiftyCam: SwiftyCamViewController, didChangeZoomLevel zoom: CGFloat) {
print("Zoom level did change. Level: \(zoom)")
print(zoom) print(zoom)
} }
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didSwitchCameras camera: SwiftyCamViewController.CameraSelection) { func swiftyCam(_ swiftyCam: SwiftyCamViewController, didSwitchCameras camera: SwiftyCamViewController.CameraSelection) {
print("Camera did change to \(camera.rawValue)")
print(camera) print(camera)
} }

View file

@ -27,13 +27,13 @@ open class SwiftyCamViewController: UIViewController {
/// Enumeration for Camera Selection /// Enumeration for Camera Selection
public enum CameraSelection { public enum CameraSelection: String {
/// Camera on the back of the device /// Camera on the back of the device
case rear case rear = "rear"
/// Camera on the front of the device /// Camera on the front of the device
case front case front = "front"
} }
/// Enumeration for video quality of the capture session. Corresponds to a AVCaptureSessionPreset /// 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 // Test authorization status for Camera and Micophone
switch AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeVideo){ switch AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeVideo) {
case .authorized: case .authorized:
// already authorized // already authorized
@ -390,12 +390,9 @@ open class SwiftyCamViewController: UIViewController {
self.promptToAppSettings() self.promptToAppSettings()
case .configurationFailed: case .configurationFailed:
// Unknown Error // Unknown Error
DispatchQueue.main.async(execute: { [unowned self] in DispatchQueue.main.async {
let message = NSLocalizedString("Unable to capture media", comment: "Alert message when something goes wrong during capture session configuration") self.cameraDelegate?.swiftyCamDidFailToConfigure(self)
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)
})
} }
} }
} }

View file

@ -15,6 +15,7 @@
import UIKit import UIKit
import AVFoundation
// MARK: Public Protocol Declaration // MARK: Public Protocol Declaration
@ -95,6 +96,14 @@ public protocol SwiftyCamViewControllerDelegate: class {
*/ */
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didChangeZoomLevel zoom: CGFloat) 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 { public extension SwiftyCamViewControllerDelegate {
@ -135,6 +144,10 @@ public extension SwiftyCamViewControllerDelegate {
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didChangeZoomLevel zoom: CGFloat) { func swiftyCam(_ swiftyCam: SwiftyCamViewController, didChangeZoomLevel zoom: CGFloat) {
// Optional // Optional
} }
func swiftyCamDidFailToConfigure(_ swiftyCam: SwiftyCamViewController) {
// Optional
}
} }