SwiftUI tools to pickup photos and videos from iOS media library.
Reference: Bringing Photos picker to your SwiftUI app
Only iOS16+ is supported.
Add the package as a dependency in Package.swift
dependencies: [
.package(
url: "https://github.com/ysohma/swiftui-media-pickup",
from: "0.1.0"
),
]
Then add MediaPickup as a dependency of your target.
.executableTarget(
name: "YourApp",
dependencies: [
.product(name: "MediaPickup", package: "swiftui-media-pickup"),
]
)
Use PhotoPickupButton
import MediaPickup
struct PhotoPickup: View{
@State private var image: UIImage? = nil
var body: some View{
PhotoPickupButton(pickedImage: $image){ status in
/// Label content
/// You can switch label depending on loading status.
switch status {
case .loading(_):
ProgressView()
default:
Image(systemName: "plus")
}
}
}
}
Use VideoPickupButton
struct VideoPickup: View{
@State private var asset: AVAsset? = nil
var body: some View{
VideoPickupButton(pickedVideo: $asset){ status in
/// Label content
/// You can switch view depending on loading status.
switch status {
case .loading(_):
ProgressView()
default:
Image(systemName: "plus")
}
}
}
}
See MediaPickupDemo