I'm trying to convert a link to Data but my code is failing with most images. I don't know why it works with some images and not with others.
if provider.hasItemConformingToTypeIdentifier("public.image") {
provider.loadInPlaceFileRepresentation(forTypeIdentifier: "public.image") { image, _, err in
guard let image = image else {return}
do {
DispatchQueue.main.async {
self.parent.image = try? Data(contentsOf: image)
}
}
}
}
Post
Replies
Boosts
Views
Activity
I'm trying to figure out how to load videos with PHPicker. I know how to do it with Images but I can't seem to figure out how to do it with videos. This code works only with some videos and not with others.
Here's my code
@Binding var video: URL?
typealias UIViewControllerType = PHPickerViewController
class Coordinator: NSObject, PHPickerViewControllerDelegate {
var parent: MediaPicker
init(_ parent: MediaPicker) {
self.parent = parent
}
func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {
if results.isEmpty {
picker.dismiss(animated: true)
return
}
let provider = results.first!.itemProvider
if provider.hasItemConformingToTypeIdentifier(UTType.movie.identifier) {
provider.loadItem(forTypeIdentifier: UTType.movie.identifier) { url, err in
if err != nil {return}
if let url = url {
DispatchQueue.main.sync {
self.parent.video = url as! URL?
picker.dismiss(animated: true)
}
}
}
}
}
}