When video url save in gallery show error : Domain=NSCocoaErrorDomain Code=-1 "(null)" in swift

222 views Asked by At

-When save video url in gallery -I also set read and write permission.

error : 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 }])
            }
        }
    }
0

There are 0 answers