I have a flutter app that stores a file in the iOS applications directory for the home screen widget to display. The file path is shared using UserDefaults. The following is some sample code used:
let data = UserDefaults.init(suiteName: widgetGroupId)
let filePath = data?.string(forKey: "_filepath")
var displayMessage = "Default display message"
// if file path found
if (filePath != nil) {
let fileManager = FileManager.default
// update display message if file at filePath does not exist
if (!fileManager.fileExists(atPath: filePath!)) {
displayMessage = "Image couldn't be displayed :("
displayMessage = filePath! // TODO: remove this
}
} else {
displayMessage = "No image set yet!"
}
This works in the simulator and fileExists returns true. Upon testing on a real device, it always returns false. An example file path used on a real device is:
var/mobile/Containers/Data/Application/<UUID>/Documents/file.jpg
How do I resolve this?