无法打开NSCocoaErrorDomain Code = 257文件,因为您没有查看权限:FileManager attributesOfItem在iOS13中返回nil [英] NSCocoaErrorDomain Code=257 file couldn’t be opened because you don’t have permission to view it : FileManager attributesOfItem returns nil in iOS13

查看:61
本文介绍了无法打开NSCocoaErrorDomain Code = 257文件,因为您没有查看权限:FileManager attributesOfItem在iOS13中返回nil的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iOS 13设备中,尝试获取文件大小时,FileManager返回权限错误.

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

do {
    let attr = try FileManager.default.attributesOfItem(atPath: my_file_path) //--> Getting nil
    fileSize = attr[FileAttributeKey.size] as! UInt64
} catch {
    print("Error: \(error)")
}

返回错误:

Error Domain = NSCocoaErrorDomain代码= 257由于您无权查看文件"trim.1A9FFC19-EE2C-438A-BF3D-97E05A97EF9E.MOV",因此无法打开."UserInfo = {NSFilePath =/private/var/mobile/Containers/Data/PluginKitPlugin/ADB8684E-12B5-451D-A20F-158B899BB3DD/tmp/trim.1A9FFC19-EE2C-438A-BF3D-97E05A97EF9E.MOV,NSUnderlyingErrorError = 0x280= NSPOSIXErrorDomain代码= 1不允许操作"}}

Error Domain=NSCocoaErrorDomain Code=257 "The file "trim.1A9FFC19-EE2C-438A-BF3D-97E05A97EF9E.MOV" couldn’t be opened because you don’t have permission to view it." UserInfo={NSFilePath=/private/var/mobile/Containers/Data/PluginKitPlugin/ADB8684E-12B5-451D-A20F-158B899BB3DD/tmp/trim.1A9FFC19-EE2C-438A-BF3D-97E05A97EF9E.MOV, NSUnderlyingError=0x280af0510 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}

仅在我更新到iOS 13之后才观察到该问题.在早期版本中,一切正常.

The issue observed only after I updated to iOS 13. In earlier versions everything is working fine.

推荐答案

iOS 13 SDK将照片应用程序视为另一个应用程序,因此当我们关闭图像选择器控制器时,视频网址将无效.

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

在尝试将视频上传到AWS之前,我遇到了问题,我只是创建了一个临时文件夹并在关闭Image-picker之前复制了现有的视频URL路径,然后将其上传,就可以了.

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

   }

这篇关于无法打开NSCocoaErrorDomain Code = 257文件,因为您没有查看权限:FileManager attributesOfItem在iOS13中返回nil的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆