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

后端 未结 1 1104
南方客
南方客 2021-01-04 21:11

FileManager returns permission error while trying to get the file size, in iOS 13 devices.

do {
    let attr = try FileManager.default.attributesOfItem(atPat         


        
1条回答
  •  走了就别回头了
    2021-01-04 21:40

    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)
                  }
    
       }
    

    0 讨论(0)
提交回复
热议问题