Skip to content
This repository has been archived by the owner on Jul 1, 2022. It is now read-only.

Fix for endless loop : canceling libary --> taking picture automatically #270

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .swift-version

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
14 changes: 0 additions & 14 deletions ALCameraViewController.podspec

This file was deleted.

611 changes: 0 additions & 611 deletions ALCameraViewController.xcodeproj/project.pbxproj

This file was deleted.

This file was deleted.

19 changes: 0 additions & 19 deletions CameraViewController/CameraViewController.h

This file was deleted.

26 changes: 0 additions & 26 deletions CameraViewController/Info.plist

This file was deleted.

2 changes: 1 addition & 1 deletion Example/Supporting Files/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0.10</string>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
31 changes: 31 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "ALCameraViewController",
platforms: [
.iOS(.v13)
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "ALCameraViewController",
targets: ["ALCameraViewController"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "ALCameraViewController",
dependencies: [],
resources: [
.process("CameraView.strings")
])
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@

"permissions.settings" = "Settings";

"error.cant-fetch-photo" = "Unable to fetch image";
"error.cant-fetch-photo.description" = "Please check your network settings";
"error.cant_fetch_photo" = "Unable to fetch image";
"error.cant_fetch_photo.description" = "Please check your network settings";
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal let scale = UIScreen.main.scale
public class CameraGlobals {
public static let shared = CameraGlobals()

public var bundle = Bundle(for: CameraViewController.self)
public var bundle = Bundle.module
public var stringsTable = "CameraView"
public var photoLibraryThumbnailSize = CGSize(width: thumbnailDimension, height: thumbnailDimension)
public var defaultCameraPosition = AVCaptureDevice.Position.back
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public func takePhoto(_ stillImageOutput: AVCaptureStillImageOutput, videoOrient
image = UIImage(cgImage: cgImage, scale: image.scale, orientation: .downMirrored)
case .downMirrored:
image = UIImage(cgImage: cgImage, scale: image.scale, orientation: .down)
@unknown default:
image = UIImage(cgImage: cgImage, scale: image.scale, orientation: .right)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ class PhotoLibraryAuthorizer {
self.onDeniedOrRestricted(completion: self.completion)
}
break
@unknown default:
DispatchQueue.main.async {
self.onDeniedOrRestricted(completion: self.completion)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class SingleImageFetcher {
private func _fetch() {

guard let asset = asset else {
let error = errorWithKey("error.cant-fetch-photo", domain: errorDomain)
let error = errorWithKey("error.cant_fetch_photo", domain: errorDomain)
failure?(error)
return
}
Expand All @@ -87,7 +87,7 @@ public class SingleImageFetcher {
if let image = image {
self.success?(image)
} else {
let error = errorWithKey("error.cant-fetch-photo", domain: self.errorDomain)
let error = errorWithKey("error.cant_fetch_photo", domain: self.errorDomain)
self.failure?(error)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public class SingleImageSaver {
}

private func invokeFailure() {
let error = errorWithKey("error.cant-fetch-photo", domain: errorDomain)
let error = errorWithKey("error.cant_fetch_photo", domain: errorDomain)
failure?(error)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ internal func errorWithKey(_ key: String, domain: String) -> NSError {
return error
}

internal func normalizedRect(_ rect: CGRect, orientation: UIImageOrientation) -> CGRect {
internal func normalizedRect(_ rect: CGRect, orientation: UIImage.Orientation) -> CGRect {
let normalizedX = rect.origin.x
let normalizedY = rect.origin.y

Expand All @@ -86,6 +86,8 @@ internal func normalizedRect(_ rect: CGRect, orientation: UIImageOrientation) ->
normalizedRect = CGRect(x: 1-normalizedY-normalizedHeight, y: normalizedX, width: normalizedHeight, height: normalizedWidth)
case .right, .rightMirrored:
normalizedRect = CGRect(x: normalizedY, y: 1-normalizedX-normalizedWidth, width: normalizedHeight, height: normalizedWidth)
@unknown default:
normalizedRect = CGRect(x: normalizedX, y: normalizedY, width: normalizedWidth, height: normalizedHeight)
}

return normalizedRect
Expand All @@ -100,6 +102,8 @@ internal func flashImage(_ mode: AVCaptureDevice.FlashMode) -> String {
image = "flashOnIcon"
case .off:
image = "flashOffIcon"
@unknown default:
image = "flashAutoIcon"
}
return image
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import MediaPlayer

typealias VolumeChangeAction = (Float) -> Void

public class VolumeControl {
public class VolumeControl : NSObject {

let changeKey = "AVSystemController_SystemVolumeDidChangeNotification"

Expand All @@ -25,12 +25,15 @@ public class VolumeControl {
var onVolumeChange: VolumeChangeAction?

init(view: UIView, onVolumeChange: VolumeChangeAction?) {
super.init()
self.onVolumeChange = onVolumeChange
view.addSubview(volumeView)
view.sendSubview(toBack: volumeView)

try? AVAudioSession.sharedInstance().setActive(true)
NotificationCenter.default.addObserver(self, selector: #selector(volumeChanged), name: NSNotification.Name(rawValue: changeKey), object: nil)
view.sendSubviewToBack(volumeView)
do {
try AVAudioSession.sharedInstance().setActive(true)
NotificationCenter.default.addObserver(self, selector: #selector(volumeChanged), name: NSNotification.Name(rawValue: changeKey), object: nil)

} catch {}
}

deinit {
Expand All @@ -40,10 +43,18 @@ public class VolumeControl {
volumeView.removeFromSuperview()
}

@objc func volumeChanged() {
guard let slider = volumeView.subviews.filter({ $0 is UISlider }).first as? UISlider else { return }
@objc func volumeChanged(notif: Notification) {
guard
let reason = notif.userInfo?["AVSystemController_AudioVolumeChangeReasonNotificationParameter"] as? String,
reason == "ExplicitVolumeChange" else {
return
}
let volume = AVAudioSession.sharedInstance().outputVolume
slider.setValue(volume, animated: false)
let slider = volumeView.subviews.filter({ $0 is UISlider }).first as? UISlider
slider?.setValue(volume, animated: false)
onVolumeChange?(volume)
}


}

Loading