info[UIImagePickerController.InfoKey.mediaURL] 有时为零 [英] info[UIImagePickerController.InfoKey.mediaURL] is sometimes nil

查看:28
本文介绍了info[UIImagePickerController.InfoKey.mediaURL] 有时为零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个选择器,在成功选择视频后,我无法获得资产的路径.所以我有这个:

I am having a picker, and after successfully picking of video, I can't get a path to the asset. So I have this:

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {



        if let videoURL = info[UIImagePickerController.InfoKey.mediaURL] as? URL {
            MediaManager.shared.sourceType = picker.sourceType
            self.metadata.videoURL = videoURL
        }
}

一般在用手机保存的视频,甚至很多通过 iTunes 或不同工具上传的视频中,我总能找到路径.

Generally in videos saved with the phone, or even many videos uploaded through iTunes or with different tools, I always get a path.

在这种情况下,我使用 AirDrop 传输了 400mb 的高分辨率视频 (720p),当我选择它时,它的路径为零......我在这里遗漏了什么吗?

In this case, I transferred a hiRes video (720p) of 400mb, using AirDrop, and when I pick it, I get nil for its path...Am I missing something here?

我猜不是因为它的传输方式,因为我收到了相同问题的报告,使用另一个应用程序将其传输到手机.

I guess it is not because of the way it is transferred, cause I got a report for the same issue, using another app to transfer it to the phone.

推荐答案

对于所有可能的情况,您都需要这样处理

You need to handle it like this for all possible cases

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any] {

    picker.dismiss(animated: true)

    print("info[UIImagePickerController.InfoKey.mediaURL] referenceURL " , info[.referenceURL] )
    print("info[UIImagePickerController.InfoKey.mediaURL] phAsset " , info[.phAsset])
    print("info[UIImagePickerController.InfoKey.mediaURL] mediaURL " , info[.mediaURL])

    if let asset =  info[UIImagePickerController.InfoKey.phAsset] as? PHAsset {

        asset.getURL { (tempPath) in

            DispatchQueue.main.async {

            }
        }

    }
    else  if let media =  info[UIImagePickerController.InfoKey.mediaURL] as? URL {


    }
    else
        if let ref =  info[UIImagePickerController.InfoKey.referenceURL] as? URL {

            let res = PHAsset.fetchAssets(withALAssetURLs: [ref], options: nil)

            res.firstObject!.getURL { (tempPath) in

                DispatchQueue.main.async {


                }

            }

    }

}

这篇关于info[UIImagePickerController.InfoKey.mediaURL] 有时为零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆