Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 无法检索摄像机滚动雨燕5中视频的URL_Ios_Swift_Swift5 - Fatal编程技术网

Ios 无法检索摄像机滚动雨燕5中视频的URL

Ios 无法检索摄像机滚动雨燕5中视频的URL,ios,swift,swift5,Ios,Swift,Swift5,以下是我的代码: @IBAction func selectVideoButton(_ sender: UIButton) { let videoPicker = UIImagePickerController() videoPicker.sourceType = UIImagePickerController.SourceType.photoLibrary videoPicker.mediaTypes = [kUTTypeImage as String, kUTType

以下是我的代码:

@IBAction func selectVideoButton(_ sender: UIButton) {
    let videoPicker = UIImagePickerController()
    videoPicker.sourceType = UIImagePickerController.SourceType.photoLibrary
    videoPicker.mediaTypes = [kUTTypeImage as String, kUTTypeMovie as String]
    videoPicker.delegate = self
    present(videoPicker, animated: true, completion: nil)
}


func retrieveURL(_picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
    if let videoURL = info[.mediaURL] {
        print("Here is the URL: \(videoURL)")
        return
    }
}
我没有收到任何错误,应用程序在选择视频后也不会崩溃,它似乎什么都没做。抱歉,如果在某个地方有此问题的答案,无法找到与swift 5或有效的相关的答案


我尝试将“Any”改为字符串,然后相应地修改videoURL,但也没有效果。

您需要正确的委托方法

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

    if let videoURL = info[.mediaURL] {
        print("Here is the URL: \(videoURL)") 
    }
    picker.dismiss(animated:true,completion:nil) // add this 
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
   let videoURL = info[UIImagePickerControllerMediaURL] as? URL
   print(videoURL)
   imagePickerController.dismissViewControllerAnimated(true, completion: nil)
}