From 4c34592d6794dd80ded9cfcf4598baa14ac54e6d Mon Sep 17 00:00:00 2001 From: Josh Brown Date: Mon, 17 Jun 2024 11:31:42 -0400 Subject: [PATCH 1/2] Fix #1211: Taking photo/video from app does nothing --- .../ImagePickerUIViewController.swift | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/Nos/Views/New Note/ImagePickerUIViewController.swift b/Nos/Views/New Note/ImagePickerUIViewController.swift index 3042bcb5c..c619ea547 100644 --- a/Nos/Views/New Note/ImagePickerUIViewController.swift +++ b/Nos/Views/New Note/ImagePickerUIViewController.swift @@ -1,3 +1,4 @@ +import Logger import SwiftUI import UniformTypeIdentifiers @@ -30,7 +31,6 @@ struct ImagePickerUIViewController: UIViewControllerRepresentable { } final class Coordinator: NSObject, UIImagePickerControllerDelegate, UINavigationControllerDelegate { - var onCompletion: ((URL?) -> Void) init(onCompletion: @escaping ((URL?) -> Void)) { @@ -40,6 +40,7 @@ struct ImagePickerUIViewController: UIViewControllerRepresentable { func imagePickerControllerDidCancel(_ picker: UIImagePickerController) { onCompletion(nil) } + func imagePickerController( _ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any] @@ -48,9 +49,30 @@ struct ImagePickerUIViewController: UIViewControllerRepresentable { onCompletion(videoURL) } else if let imageURL = info[.imageURL] as? URL { onCompletion(imageURL) + } else if let image = info[.originalImage] as? UIImage, + let imageData = image.jpegData(compressionQuality: 1.0) { + let url = saveImage(imageData) + onCompletion(url) } else { onCompletion(nil) } } + + /// Saves the given image data to a JPG file and returns the URL of the file. + /// - Parameter imageData: The image data to save to disk. + /// - Returns: The URL of the image file. + private func saveImage(_ imageData: Data) -> URL? { + let urls = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask) + let documentDirectory = urls[0] + let fileURL = documentDirectory.appendingPathComponent("capturedImage.jpg") + + do { + try imageData.write(to: fileURL, options: .atomic) + return fileURL + } catch { + Log.debug("Error saving image: \(error)") + return nil + } + } } } From f1b34b1d6b2fa4d151a255796279a5057530ac80 Mon Sep 17 00:00:00 2001 From: Josh Brown Date: Mon, 17 Jun 2024 11:42:40 -0400 Subject: [PATCH 2/2] update CHANGELOG --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ce23643c..846533ea4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,8 +7,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] - + - Added our third cohort of creators and journalists to the Discover tab. +- Fixed a bug where taking a photo in the app didn’t work. ## [0.1.17] - 2024-06-10Z