Search code examples
iosswiftxcodensfilemanager

Swift - The file couldn’t be opened because you don’t have permission to view it


I'm saving to FileManager.default.documentDirectory the url as string for some video I select from Library. I am able to load and use them with no problem, but if I run the app again, when I load the array of url, I can't use them as I get this error:

The file couldn’t be opened because you don’t have permission to view it.

of this one

The requested URL was not found on this server.

I have tried all solutions I could find googling the errors, but nothing solve it. Any help will be much appreciated.

I'm developing for iOS. Xcode Version 11.3.1


Solution

  • The problem there is that the file path will change every time you run the app. You shouldn't save the whole file path. You can save its name and reconstruct your URL before loading it.