Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/juniperphoton/photospickerissueios18
https://github.com/juniperphoton/photospickerissueios18
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/juniperphoton/photospickerissueios18
- Owner: JuniperPhoton
- Created: 2024-09-10T08:17:58.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-09-15T11:30:14.000Z (4 months ago)
- Last Synced: 2024-09-15T13:27:33.765Z (4 months ago)
- Language: Swift
- Size: 17.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# PhotosPicker issue on iOS 18
This is a minimum demo that can replicate the PhotosPicker issue on iOS 18:
1. Run the app on iOS 18.
2. Click the "Pick photo" button, which will invoke the PhotosPicker.
3. Navigate to the "Collection" tab, and the picker will show a "failure" UI.The code is rather simple:
```swift
struct ContentView: View {
@State private var selection: PhotosPickerItem? = nil
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Hello, world!")
PhotosPicker("Pick photo", selection: $selection)
}
.padding()
}
}
```
## WorkroundWe can avoid this issue by disabling the Collections feature in PhotosPicker. However this API isn't exposed in SwiftUI. You have bridge your SwiftUI view to use `PHPickerViewController`, which is the underlying part in `PhotosPicker`.
```swift
private func createNewInstance(sizeLimit: Int) -> PHPickerViewController {
var configuration = PHPickerConfiguration(photoLibrary: .shared())
configuration.filter = PHPickerFilter.any(of: [.images])
configuration.preferredAssetRepresentationMode = .current
configuration.selection = .ordered
configuration.selectionLimit = sizeLimit
// Workaround to prevent users navigate to the Collections tab, which will crash.
// https://developer.apple.com/documentation/uikit/view_controllers/collaborating_and_sharing_copies_of_your_data
if #available(iOS 18.0, *) {
configuration.disabledCapabilities = [.collectionNavigation]
}
return PHPickerViewController(configuration: configuration)
}
```