I have a SwiftUI application that processes image files from Fujifilm cameras - both raw and jpeg. When the image files are imported into the Photos app they are stacked so that you see only a single image when there are both raw and jpeg versions of the same image. Using Swift I cannot work out how to access both files - using the following code you get the jpeg file or the raw file if there is only a single file - but if there are both raw and jpeg files you only get the jpeg file.
import SwiftUI
import PhotosUI
struct PhotoPicker1: UIViewControllerRepresentable {
typealias UIViewControllerType = PHPickerViewController
@ObservedObject var mediaItems: PickedMediaItems
var didFinishPicking: (_ didSelectItems: Bool) -> Void
func makeUIViewController(context: Context) -> PHPickerViewController {
var config = PHPickerConfiguration(photoLibrary: .shared())
config.filter = .any(of: [.images])
config.selectionLimit = 0
config.preferredAssetRepresentationMode = .current
let controller = PHPickerViewController(configuration: config)
controller.delegate = context.coordinator
return controller
}
func updateUIViewController(_ uiViewController: PHPickerViewController, context: Context) { }
func makeCoordinator() -> Coordinator { Coordinator(with: self) }
class Coordinator: PHPickerViewControllerDelegate {
var photoPicker1: PhotoPicker1
init(with photoPicker1: PhotoPicker1) {
self.photoPicker1 = photoPicker1
}
func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {
photoPicker1.didFinishPicking(!results.isEmpty)
guard !results.isEmpty else {
return
}
for result in results {
let itemProvider = result.itemProvider
let typeIdentifier = itemProvider.registeredTypeIdentifiers.first ?? ""
print("typeIdentifier: \(typeIdentifier)")
}
}
}
}