mirror of
https://github.com/samsonjs/SwiftyCam.git
synced 2026-04-08 11:25:52 +00:00
Added delegate for failed configuration
This commit is contained in:
parent
2f4784ae39
commit
85d9bc917c
3 changed files with 30 additions and 10 deletions
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue