ios - 当视频 url 保存在画廊中时显示错误:Domain=NSCocoaErrorDomain Code=-1 "(null)" in swift
问题描述
- 当在图库中保存视频网址时 - 我还设置了读写权限。
错误:Domain=NSCocoaErrorDomain Code=-1 "(null)" in swift。
private func saveVideoToPhotos(url : URL?) {
if let url = url, let urlData = NSData(contentsOf: url) {
let galleryPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0];
let filePath = galleryPath.appending("/videoFileName.mp4")
print(filePath)
DispatchQueue.main.async {
urlData.write(toFile: filePath, atomically: false)
PHPhotoLibrary.shared().performChanges({
PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL:URL(fileURLWithPath: filePath))
}) {
success, error in
if success {
print("Succesfully Saved")
} else {
DispatchQueue.main.async {
print(error.debugDescription)
self.popupAlert(title: "Request failed.please try again later!", actionTitles: ["ok"], actionStyle: [.default], action: [{_ in }])
}
}
}
}
}else{
DispatchQueue.main.async {
self.popupAlert(title: "Request failed.please try again later!", actionTitles: ["ok"], actionStyle: [.default], action: [{_ in }])
}
}
}
解决方案
推荐阅读
- python - 自动点检测
- c# - 有没有一种方法可以访问 appsettings.json 配置而不需要类中的构造函数我试图从中访问它
- javascript - 在 React 中如何确定事件所附加的元素?
- python - 将 3D 三角剖分曲面展开为平面 2D 图
- c - 使用 uint64_t 的不便之处
- mysql - 如何使用 substr 对我的字符串列进行排序并在 mysql 中进行强制转换
- javascript - 在 PHP 中我使用 htmlspecialchars_decode,javascript 中的等价物是什么?
- html - 三个图像居中,并排,位于页面中间
- sql - Postgresql:从日期范围内的多个版本中仅计算一次值
- ruby-on-rails - 如何在没有`bundle exec`的情况下对rails进行rubocop?