This commit is contained in:
fmodf 2024-07-09 14:43:38 +02:00
parent 3361b828ef
commit 8da928e237

View file

@ -388,23 +388,18 @@ struct CameraPicker: UIViewControllerRepresentable {
} }
func imagePickerController(_: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) { func imagePickerController(_: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
if let mediaType = info[.mediaType] as? UTType { // swiftlint:disable:next force_cast
switch mediaType { let mediaType = info[.mediaType] as! String
case .image:
if let image = info[.originalImage] as? UIImage {
let data = image.jpegData(compressionQuality: 1.0) ?? Data()
parent.completionHandler(data, .image)
}
case .movie: if mediaType == UTType.image.identifier {
if let url = info[.mediaURL] as? URL { if let image = info[.originalImage] as? UIImage {
let data = try? Data(contentsOf: url) let data = image.jpegData(compressionQuality: 1.0) ?? Data()
parent.completionHandler(data ?? Data(), .movie) parent.completionHandler(data, .image)
} }
parent.completionHandler(Data(), .movie) } else if mediaType == UTType.movie.identifier {
if let url = info[.mediaURL] as? URL {
default: let data = try? Data(contentsOf: url)
break parent.completionHandler(data ?? Data(), .movie)
} }
} }
} }