Ios 尝试在UIImagePickerController didFinishPickingMediaWithInfo回调中移动文件失败,返回“0”;你没有';“我没有许可”;错误

Ios 尝试在UIImagePickerController didFinishPickingMediaWithInfo回调中移动文件失败,返回“0”;你没有';“我没有许可”;错误,ios,ios13.7,Ios,Ios13.7,以下是显示图像选择器的代码: let pickerController = UIImagePickerController() pickerController.delegate = self pickerController.allowsEditing = false pickerController.mediaTypes = [kUTTypeMovie as String] pickerController.so

以下是显示图像选择器的代码:

        let pickerController = UIImagePickerController()
        pickerController.delegate = self
        pickerController.allowsEditing = false
        pickerController.mediaTypes = [kUTTypeMovie as String]
        pickerController.sourceType = .photoLibrary
在代表中,我有:

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
    guard let videoURL = info[.mediaURL] as? URL
        else { return }
    do {
        let newFileLocation = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString + ".mov")
        FileManager.default.moveItem(at: videoURL, to: newFileLocation)
    } catch {
        // “trim.92501481-FA5B-490C-8F55-575DE076C8A1.MOV” couldn’t be moved because you don’t have permission to access “tmp”
    }
}
我回去在iOS 13.5上试过了,效果很好,但在iOS 13.7中我遇到了一个奇怪的错误。

啊,简单的修复,更改:

FileManager.default.moveItem(at: videoURL, to: newFileLocation)


@马特:好的,我编辑了它,但这不是问题的根源,我只是为SOExcellent即兴创作了这一部分!我之前没有建议的原因是我假设你不想复制,因为它太耗时了。我更关心的是确保视频上传的可靠性——使用url会话的后台上传api。是的,到目前为止工作得很好
FileManager.default.copyItem(at: videoURL, to: newFileLocation)