-2

Trying to allow user to upload video from camera roll using PHPickerViewController (eventually to firebase storage) which is why I'm trying to get the url, but I'm getting this annoying error:

Error Domain=NSItemProviderErrorDomain Code=-1000 "Cannot load representation of type public.video" UserInfo={NSLocalizedDescription=Cannot load representation of type public.video}

Here is some code:

func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult])
    {
        dismiss(animated: true, completion: nil)
        guard let itemProvider = results.first?.itemProvider else { print("isbeingcalled"); return }
        
        itemProvider.loadFileRepresentation(forTypeIdentifier: UTType.video.identifier)
        { (url, error) in
            guard error == nil else { print(error!); return /**Alert**/ }
            
            print(url!)
        }

I've seen some other posts saying it might be a bug, so if it is, then what should I do?

EAO123
  • 55
  • 9

1 Answers1

1

Change

UTType.video.identifier

To

UTType.movie.identifier
matt
  • 515,959
  • 87
  • 875
  • 1,141
  • I've tried both, does not work. – EAO123 Sep 26 '21 at 13:21
  • Well it works for me. Can you tell me how to make it not work? – matt Sep 26 '21 at 13:21
  • It gives me a longer error: `"Cannot load representation of type public.movie" UserInfo={NSLocalizedDescription=Cannot load representation of type public.movie, NSUnderlyingError=0x600003598f30 {Error Domain=NSCocoaErrorDomain Code=4101 "Couldn’t communicate with a helper application." UserInfo={NSUnderlyingError=0x6000035911d0 {Error Domain=PHAssetExportRequestErrorDomain Code=4 "(null)" UserInfo={NSUnderlyingError=0x6000035913b0 {Error Domain=CloudPhotoLibraryErrorDomain Code=1006 "Failed to download CPLResourceTypeOriginal" UserInfo=0x600002ec9b80 (not displayed)}}}}}` – EAO123 Sep 26 '21 at 13:24
  • Also note that you really should always call `canLoad` so you don't get into a crash situation. What if the user chooses a still image? – matt Sep 26 '21 at 13:24
  • 1
    Ah. So this video is in the cloud? – matt Sep 26 '21 at 13:25
  • The actual code compiles but the error is printed, i think that might be the confusion. – EAO123 Sep 26 '21 at 13:28
  • No, I'm not confused. – matt Sep 26 '21 at 13:29
  • I've configured it as such `configuration.filter = PHPickerFilter.videos` and yes this video is in the cloud, within the user's camera roll, I'll try calling canLoad. – EAO123 Sep 26 '21 at 13:30
  • Well there you are then. You really should have revealed that little secret in the question. – matt Sep 26 '21 at 13:30
  • What do I do for class?, (like UIImage.self or PHLivePhoto.self) – EAO123 Sep 26 '21 at 13:40
  • Wait, the user shouldn't be able to choose an image since the configuration will only display videos in their camera roll. – EAO123 Sep 26 '21 at 13:43