When I save a file to iCloud, when the app shuts down, the file is not there anymore.
Here is my code before the app shuts down with the print results in comments beside the print statements:
FileManager.default.createFile(atPath: saveToURL.path, contents: dataImage, attributes: nil)
print("??? \(saveToURL.path) imagePicker file exists=", FileManager.default.fileExists(atPath: saveToURL.path)) // ??? /private/var/mobile/Library/Mobile Documents/iCloud~us~gnolaum~TrialVisionBoard/12BF0AB3-C0EB-4D13-A37E-7853839225BD.jpg cellForRowAt file exists= false
Notice that when the code checks if the file exists after the file is created, it checks out true.
Following is the code after the app starts again:
print("??? \(mediaURL.path) cellForRowAt file exists=", FileManager.default.fileExists(atPath: mediaURL.path)) // ??? /private/var/mobile/Library/Mobile Documents/iCloud~us~gnolaum~TrialVisionBoard/12BF0AB3-C0EB-4D13-A37E-7853839225BD.jpg cellForRowAt file exists= false
Notice that the url path is identical to the path before the app shut down but the file after the app restarts does not exist.
I suspect I need to set the correct attributes for the file I create. Anyone know what exactly I need to do to get the file to stay saved in iCloud?
ADDITIONAL CONTENT:
I noticed that I don't have this problem when I run the project on iPhone 5 Simulator. The problem occurs when I run the project on my iPhone 5 device.