File "" cannot be opened because you do not have permission to view

I upload the file to a folder and I check that the file is really present in the code, but I get the above error. Can someone help me figure out why I do not have permission 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) }

Domain Error = NSCocoaErrorDomain Code = 257 "The Documents file cannot be opened because you do not 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"}}

+5
source share
4 answers

URL - FOLDER . FILE, :

//////7FA4D6A9-2149-4053-BF08-22E94A00AE34/

+4

. , .

var filename = self.getDocumentsDirectory().appendingPathComponent(local[i])

URL-, , . ,

0

Building Setting. enter image description here, .

Since we all have iphone5s armv7 && arm64, so I only change Build Active Architecture to None. It works.enter image description here

0
source

Try

fileURL.startAccessingSecurityScopedResource()
//...
fileURL.stopAccessingSecurityScopedResource()
0
source

All Articles