Permission Denied when read a local file using Data(contentsOf: URL)

468 views Asked by At

The file I'm reading is (let data = try Data(contentsOf: url) ...

 url: file:///var/mobile/Containers/Data/Application/15666F33-0EA8-4F1B-BFBA-634EEE9FC97D/Documents/Attachments/Documents/test.numbers

But an error was caught which says Permission Denied

This is a file imported using UIDocumentPicker with import mode and moved to local folder using FileManager.default.moveItem(at: url, to: newURL)

The file does exist, and UIDocumentInteractionController does open it successfully with the same url.

I guess the access control of the original file is copied by UIDocumentPicker as well. But I have no idea how to resolve this issue.

Any help would be really appreciated. Thanks in advance.

0

There are 0 answers