Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Live Preview #39

Merged
merged 24 commits into from
Apr 9, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
87f2273
Add new camera button
daveluong Apr 4, 2019
f502787
Add PhotoGalleryLiveViewCell to show live preview of camera stream
daveluong Apr 4, 2019
ed2b84e
Make live preview a configurable
daveluong Apr 4, 2019
d52ddce
Fix setting wrong cell type & other minor code presentation
daveluong Apr 4, 2019
faddd5f
Update version to 1.4.1 & add missing files
daveluong Apr 4, 2019
7c762bd
Show old camera cell if there is no camera permission
daveluong Apr 4, 2019
c16a310
Update PhotoGalleryViewController.swift
daveluong Apr 4, 2019
23498fb
Remove Example/Pods/*
daveluong Apr 5, 2019
f485fbb
Refactor to decouple camera session handling from the cell
daveluong Apr 5, 2019
88db04e
Set version to 1.4.0
daveluong Apr 5, 2019
d05ca38
Rename property
daveluong Apr 5, 2019
3f1cbfd
Remove unused code
daveluong Apr 5, 2019
d0a003e
Remove codesign config
daveluong Apr 5, 2019
5d4a624
Missing scheme
daveluong Apr 5, 2019
cfd9113
Update CHANGELOG.md
daveluong Apr 5, 2019
4682bb9
Merge branch 'master' into feature/live-preview
daveluong Apr 8, 2019
fd69328
Make property private and fix typo
daveluong Apr 8, 2019
e1deb1e
Initialize session handler only if config has livePreviewEnabled = true
daveluong Apr 8, 2019
dc7d981
Only access capture device when starting a session
daveluong Apr 8, 2019
929302a
Make selectedAssets publicly accessible
daveluong Apr 8, 2019
4e6e808
Don't initialize the session handler if don't have permission
daveluong Apr 8, 2019
680c6e6
Use delegate instead of making the property publicly accessible
daveluong Apr 8, 2019
28d2ed4
Add method to update selectedAsset from camera to photoGallery
daveluong Apr 8, 2019
9ae0bf8
Update README.md
daveluong Apr 9, 2019
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
22 changes: 12 additions & 10 deletions Pickle/Classes/CameraSessionHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,24 @@ final class CameraSessionHandler {
return session.isRunning
}

init() throws {
var hasPermssion: Bool {
return AVCaptureDevice.authorizationStatus(for: .video) == .authorized
}

private let sessionQueue = DispatchQueue(label: "pickle.liveView.sessionQueue")

func startSession() throws {
guard hasPermssion else {
throw CameraSessionError.noPermission
}
guard
let input = AVCaptureDevice.default(for: .video),
let deviceInput = try? AVCaptureDeviceInput(device: input) else {
throw CameraSessionError.noDeviceInput
Copy link
Contributor Author

@daveluong daveluong Apr 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accessing AVCaptureDeviceInput in the initializer will prematurely prompt user for permission, so I have moved it to startSession() instead. We only use the live view when user has already granted permission previously

}

guard AVCaptureDevice.authorizationStatus(for: .video) == .authorized else {
throw CameraSessionError.noPermission
if session.inputs.count == 0 {
session.addInput(deviceInput)
}
session.addInput(deviceInput)
}

private let sessionQueue = DispatchQueue(label: "pickle.liveView.sessionQueue")

func startSession() {
sessionQueue.async { [weak self] in
guard self?.session.isRunning == .some(false) else { return }
self?.session.startRunning()
Expand Down
4 changes: 2 additions & 2 deletions Pickle/Classes/PhotoGalleryViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ internal final class PhotoGalleryViewController: UIViewController,

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
sessionHandler?.startSession()
try? sessionHandler?.startSession()
}

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
Expand All @@ -151,7 +151,7 @@ internal final class PhotoGalleryViewController: UIViewController,

internal func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if isCameraCompatible && indexPath.row == 0 {
if configuration?.isLiveCameraViewEnabled == .some(true) {
if sessionHandler?.hasPermssion == .some(true) {
let cell = collectionView.dequeueReusableCell(
withReuseIdentifier: String(describing: PhotoGalleryLiveViewCell.self),
for: indexPath
Expand Down