edonv/swiftuiphpicker
`SwiftUI` wrapper of [`PhotoKit`](https://developer.apple.com/documentation/photokit)'s [`PHPickerViewController`](https://developer.apple.com/documentation/photokit/phpickerviewcontroller).
To-Do's
- [x] Add support for multiple selections.
- [ ] Add support for selecting other Live Photos (currently only supports standard photos).
- [x] Add support for videos.
- Currently, this works but requires the developer to use videoDestination or videoDestinationDirectory. Would it be better to just internally save it to the temporary directory and return that and require that they clean it up after?
- [ ] Rework code to (by default) return
[PHPickerResult], then move async mapping code toasyncstatic function to do separately (or maybe as an extension on[PHPickerResult]?)
- Also add interoperability with native newer PhotosPicker (and PhotosPickerItem/Transferable).
Usage
import SwiftUI
import SwiftUIPHPicker
struct ContentView: View {
@State private var showPicker = false
var body: some View {
Text("Hello world!")
.sheet(isPresented: $showPicker) {
PHPicker(photoLibrary: .shared()) { result in
switch result {
case .success(let selection):
// Process selected assets
case .failure(let error):
// Deal with error
}
}
.maxSelectionCount(5)
.filter(.all(of: [.images, .not(.livePhotos), .videos]))
.videoDestinationDirectory(DOCUMENT DIRECTORY) /* more code needed for this */
}
}
}Notes
- If you'd like to support video selections, then you must use either the
setVideoDestinationDirectory(:)orsetVideoDestinationHandler(:)view modifier. Without them, there won't be somewhere set to save the video file and the system's temporary file will be be deleted before it's accessible.
Package Metadata
Repository: edonv/swiftuiphpicker
Default branch: main
README: README.md