首页 > 解决方案 > 当视频 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 }])
            }
        }
    }

标签: iosswiftphphotolibrary

解决方案


推荐阅读