NSCocoaErrorDomain Code=257 file couldn’t be opened because you don’t have permission to view it : FileManager attributesOfItem returns nil in iOS13

故事扮演 提交于 2019-12-05 06:26:52

iOS 13 SDK consider photo app as an another app, so when we dismiss the image picker controller video url will be invalidate.

I had the problem before when I try to upload video to AWS, what i did just create a temporary folder and copy the existing video url path before dismiss the Image-picker.then it upload, it's worked.

    func createDirectory(videoURL:URL){
            let Directorypath = getDirectoryPath()
            var objcBool:ObjCBool = true
            let isExist =  FileManager.default.fileExists(atPath:Directorypath,isDirectory: &objcBool)
            // If the folder with the given path doesn't exist already, create it
            if isExist == false{
                do{
                    try FileManager.default.createDirectory(atPath: Directorypath, withIntermediateDirectories: true, attributes: nil)
                }catch{

                    print("Something went wrong while creating a new folder")
                }
            }
            let fileManager = FileManager()

            do {
                if fileManager.fileExists(atPath:Directorypath) {
                    try? fileManager.removeItem(at: URL(fileURLWithPath:Directorypath))
                }
                try fileManager.copyItem(at:videoURL.absoluteURL, to: URL(fileURLWithPath:Directorypath))

                 self.imagePicker.dismiss(animated: true, completion:nil)
              }catch let error {
                              print(error.localizedDescription)
              }

   }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!