Reputation: 115
I am loading a video from the user's photo library. I want to track the progress of loadTransferable
to update a progress view. However, I am having a ton of trouble observing the key values.
I have tried creating an observable object as well, but I can never get the code in the observe
closure to run.
Does anyone have any ideas? Thanks in advance :)
import SwiftUI
import Photos
import PhotosUI
struct ContentView: View {
@State private var selectedVideo: PhotosPickerItem?
@State private var observation: NSKeyValueObservation?
private func processSelectedVideo() {
let progress = selectedVideo!.loadTransferable(type: Data.self) { result in
Task {
// do something
}
}
observation = progress.observe(\.fractionCompleted, changeHandler: { progress, value in
// this never runs
print(value)
})
progress.resume()
}
}
Upvotes: 2
Views: 347
Reputation: 6092
As of Nov 24 this is not yet resolved. Here is a post by an Apple engineer referencing the known issue:
Thanks for the report! This is a known issue and is tracked by 133331523. To receive a valid progress, please use UIKit PHPickerViewController until 133331523 is addressed.
https://developer.apple.com/forums/thread/768863
Upvotes: 0