mirror of
https://github.com/samsonjs/SwiftyCam.git
synced 2026-04-27 15:07:43 +00:00
Hopefully fixing camera issue
This commit is contained in:
parent
a3a8c6e3c1
commit
a7474d5bcc
1 changed files with 41 additions and 4 deletions
|
|
@ -243,6 +243,10 @@ open class SwiftyCamViewController: UIViewController {
|
|||
|
||||
fileprivate var deviceOrientation : UIDeviceOrientation?
|
||||
|
||||
/// Boolean to store when View Controller is notified session is running
|
||||
|
||||
fileprivate var sessionRunning = false
|
||||
|
||||
/// Disable view autorotation for forced portrait recorindg
|
||||
|
||||
override open var shouldAutorotate: Bool {
|
||||
|
|
@ -340,11 +344,22 @@ open class SwiftyCamViewController: UIViewController {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: ViewWillAppear
|
||||
|
||||
/// ViewWillAppear(_ animated:) Implementation
|
||||
|
||||
open override func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(captureSessionDidStartRunning), name: .AVCaptureSessionDidStartRunning, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(captureSessionDidStopRunning), name: .AVCaptureSessionDidStopRunning, object: nil)
|
||||
}
|
||||
|
||||
|
||||
|
||||
// MARK: ViewDidAppear
|
||||
|
||||
/// ViewDidAppear(_ animated:) Implementation
|
||||
|
||||
|
||||
override open func viewDidAppear(_ animated: Bool) {
|
||||
super.viewDidAppear(animated)
|
||||
|
||||
|
|
@ -393,6 +408,9 @@ open class SwiftyCamViewController: UIViewController {
|
|||
override open func viewDidDisappear(_ animated: Bool) {
|
||||
super.viewDidDisappear(animated)
|
||||
|
||||
NotificationCenter.default.removeObserver(self)
|
||||
sessionRunning = false
|
||||
|
||||
// If session is running, stop the session
|
||||
if self.isSessionRunning == true {
|
||||
self.session.stopRunning()
|
||||
|
|
@ -424,6 +442,7 @@ open class SwiftyCamViewController: UIViewController {
|
|||
return
|
||||
}
|
||||
|
||||
|
||||
if device.hasFlash == true && flashEnabled == true /* TODO: Add Support for Retina Flash and add front flash */ {
|
||||
changeFlashSettings(device: device, mode: .on)
|
||||
capturePhotoAsyncronously(completionHandler: { (_) in })
|
||||
|
|
@ -831,6 +850,12 @@ open class SwiftyCamViewController: UIViewController {
|
|||
}
|
||||
|
||||
fileprivate func capturePhotoAsyncronously(completionHandler: @escaping(Bool) -> ()) {
|
||||
|
||||
guard sessionRunning == true else {
|
||||
print("[SwiftyCam]: Cannot take photo while session isn't running")
|
||||
return
|
||||
}
|
||||
|
||||
if let videoConnection = photoFileOutput?.connection(withMediaType: AVMediaTypeVideo) {
|
||||
|
||||
photoFileOutput?.captureStillImageAsynchronously(from: videoConnection, completionHandler: {(sampleBuffer, error) in
|
||||
|
|
@ -994,6 +1019,18 @@ open class SwiftyCamViewController: UIViewController {
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
/// Called when Notification Center registers session starts running
|
||||
|
||||
@objc private func captureSessionDidStartRunning() {
|
||||
sessionRunning = true
|
||||
}
|
||||
|
||||
/// Called when Notification Center registers session stops running
|
||||
|
||||
@objc private func captureSessionDidStopRunning() {
|
||||
sessionRunning = false
|
||||
}
|
||||
}
|
||||
|
||||
extension SwiftyCamViewController : SwiftyCamButtonDelegate {
|
||||
|
|
|
|||
Loading…
Reference in a new issue