无法打开文件“",因为您没有查看权限 [英] The file “ ” couldn’t be opened because you don’t have permission to view it
问题描述
我正在将文件下载到文件夹,并且正在验证代码中确实存在该文件,但是出现上述错误.有人可以帮我弄清楚为什么我没有读取此文件的权限吗?
I am downloading a file to a folder and I am validating that the file is indeed there in the code, but I am getting the above error. Can someone help me figure out why i dont have permissions to read this file?
let documentsURL = NSSearchPathForDirectoriesInDomains
(.DocumentDirectory, .UserDomainMask, true)[0]
let checkValidation = NSFileManager.defaultManager()
if (checkValidation.fileExistsAtPath(documentsURL))
{
print("FILE AVAILABLE");
}
else
{
print("FILE NOT AVAILABLE");
}
print(documentsURL)
do{
let data = try String(contentsOfFile: documentsURL as String,
encoding: NSASCIIStringEncoding)
print(data)
}
catch let error { print(error) }
Error Domain = NSCocoaErrorDomain代码= 257无法打开文件文档",因为您没有查看权限." UserInfo = {NSFilePath =/var/mobile/Containers/Data/Application/7FA4D6A9-2149-4053-BF08-22E94A00AE34/Documents,NSUnderlyingError = 0x137807200 {Error Domain = NSPOSIXErrorDomain代码= 13权限被拒绝"}}
Error Domain=NSCocoaErrorDomain Code=257 "The file "Documents" couldn’t be opened because you don’t have permission to view it." UserInfo={NSFilePath=/var/mobile/Containers/Data/Application/7FA4D6A9-2149-4053-BF08-22E94A00AE34/Documents, NSUnderlyingError=0x137807200 {Error Domain=NSPOSIXErrorDomain Code=13 "Permission denied"}}
推荐答案
尝试
fileURL.startAccessingSecurityScopedResource()
//...
fileURL.stopAccessingSecurityScopedResource()
这篇关于无法打开文件“",因为您没有查看权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!