Skip to content

Commit

Permalink
Patch 3.0.1
Browse files Browse the repository at this point in the history
fix:
- Fixed an issue with the application crashing when permissions were not granted (#73)
- Fixed other minor bugs
  • Loading branch information
FulcrumOne authored Dec 16, 2024
1 parent 8cde880 commit 5963b61
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion MijickCamera.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Pod::Spec.new do |s|
Camera made simple. The ultimate camera library that significantly reduces implementation time and effort. Written with and for SwiftUI.
DESC

s.version = '3.0.0'
s.version = '3.0.1'
s.ios.deployment_target = '14.0'
s.swift_version = '6.0'

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ private extension CameraManagerNotificationCenter {
// MARK: Reset
extension CameraManagerNotificationCenter {
func reset() {
NotificationCenter.default.removeObserver(self, name: .AVCaptureSessionWasInterrupted, object: parent.captureSession)
NotificationCenter.default.removeObserver(self, name: .AVCaptureSessionWasInterrupted, object: parent?.captureSession)
}
}
19 changes: 13 additions & 6 deletions Sources/Internal/Manager/CameraManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import AVKit
private(set) var captureSession: any CaptureSession
private(set) var frontCameraInput: (any CaptureDeviceInput)?
private(set) var backCameraInput: (any CaptureDeviceInput)?
private(set) var audioInput: (any CaptureDeviceInput)?

// MARK: Output
private(set) var photoOutput: CameraManagerPhotoOutput = .init()
Expand All @@ -37,11 +36,10 @@ import AVKit
private(set) var notificationCenterManager: CameraManagerNotificationCenter = .init()

// MARK: Initializer
init<CS: CaptureSession, CDI: CaptureDeviceInput>(captureSession: CS, fontCameraInput: CDI?, backCameraInput: CDI?, audioInput: CDI?) {
init<CS: CaptureSession, CDI: CaptureDeviceInput>(captureSession: CS, captureDeviceInputType: CDI.Type) {
self.captureSession = captureSession
self.frontCameraInput = fontCameraInput
self.backCameraInput = backCameraInput
self.audioInput = audioInput
self.frontCameraInput = CDI.get(mediaType: .video, position: .front)
self.backCameraInput = CDI.get(mediaType: .video, position: .back)
}
}

Expand Down Expand Up @@ -80,7 +78,7 @@ private extension CameraManager {
}
func setupDeviceInputs() throws(MCameraError) {
try captureSession.add(input: getCameraInput())
if attributes.isAudioSourceAvailable { try captureSession.add(input: audioInput) }
if let audioInput = getAudioInput() { try captureSession.add(input: audioInput) }
}
func setupDeviceOutput() throws(MCameraError) {
try photoOutput.setup(parent: self)
Expand All @@ -102,6 +100,15 @@ private extension CameraManager {
}}
}
private extension CameraManager {
func getAudioInput() -> (any CaptureDeviceInput)? {
guard attributes.isAudioSourceAvailable,
let deviceInput = frontCameraInput ?? backCameraInput
else { return nil }

let captureDeviceInputType = type(of: deviceInput)
let audioInput = captureDeviceInputType.get(mediaType: .audio, position: .unspecified)
return audioInput
}
nonisolated func startCaptureSession() async throws {
await captureSession.startRunning()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ class MockCaptureSession: NSObject, CaptureSession { required override init() {}


extension MockCaptureSession {
func startRunning() {
func startRunning() { Task { @MainActor in
_isRunning = true
}
}}
func stopRunningAndReturnNewInstance() -> any CaptureSession {
_isRunning = false
return MockCaptureSession()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ import SwiftUI
@MainActor class CameraFocusIndicatorView {
var image: UIImage = .init(resource: .mijickIconCrosshair)
var tintColor: UIColor = .init(resource: .mijickBackgroundYellow)
var size: CGFloat = 92
var size: CGFloat = 96
}

// MARK: Create
extension CameraFocusIndicatorView {
func create(at touchPoint: CGPoint) -> UIImageView {
let focusIndicator = UIImageView(image: image)
focusIndicator.contentMode = .scaleAspectFit
focusIndicator.tintColor = tintColor
focusIndicator.frame.size = .init(width: size, height: size)
focusIndicator.frame.origin.x = touchPoint.x - size / 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ import AVKit
public extension MCamera {
init() { self.init(manager: .init(
captureSession: AVCaptureSession(),
fontCameraInput: AVCaptureDeviceInput.get(mediaType: .video, position: .front),
backCameraInput: AVCaptureDeviceInput.get(mediaType: .video, position: .back),
audioInput: AVCaptureDeviceInput.get(mediaType: .audio, position: .unspecified)
captureDeviceInputType: AVCaptureDeviceInput.self
))}
}

Expand Down
6 changes: 2 additions & 4 deletions Tests/Tests+CameraManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ import SwiftUI
@MainActor @Suite("Camera Manager Tests") struct CameraManagerTests {
var cameraManager: CameraManager = .init(
captureSession: MockCaptureSession(),
fontCameraInput: MockDeviceInput.get(mediaType: .video, position: .front),
backCameraInput: MockDeviceInput.get(mediaType: .video, position: .back),
audioInput: MockDeviceInput.get(mediaType: .audio, position: .unspecified)
captureDeviceInputType: MockDeviceInput.self
)
}

Expand Down Expand Up @@ -385,7 +383,7 @@ private extension CameraManagerTests {

cameraManager.initialize(in: cameraView)
try await cameraManager.setup()
await Task.sleep(seconds: 2)
await Task.sleep(seconds: 10)
}
}
private extension CameraManagerTests {
Expand Down

0 comments on commit 5963b61

Please sign in to comment.