Context: Xcode 8.3.2 / Swift 3
I'm downloading a bunch of MP3s in a subfolder inside the Documents folder. Then, I'm verifying success by:
try FileManager.default.contentsOfDirectory(atPath: folderPath)I can see my files listed- using Xcode, I'm doing Window - Devices - myDevice - myApp - downloadContainer. I get a copy of the sandbox on my computer's desktop. I navigate to the relevant subfolder in the Documents folder and sure enough, my MP3s are there
- last but not least...in my mobile app, I simply select one of the downloaded MP3s and hit play. It plays.
Then, I restart the application. No saved song would play again, for the above reason: The file "name_here" couldn’t be opened because there is no such file. FileManager.default.contentsOfDirectory() still lists them there; when I check the sandbox they're all there.
I'm out of ideas. Ideas, anyone ?
PS: the error happens when I
try Data.init(contentsOf: URL(fileURLWithPath: file_path_here))
Normally I wouldn't really need to load the stuff in memory; AVPlayer plays them just fine from disk; however, I must decrypt them first, that's why I'm populating a "NSData" with the content of whatever file. Useless to say, nothing reaches my decryptor because...The file couldn’t be opened because there is no such file
Why would the same code work the first time (when I download them) but fail in a later session ???