Any possible reason why files in www folder load ok in emulator but not in device?
The files seem to load correctly from www folder when the app is run in emulator, but not when run from the device (iPhone SE 1gen).
Any possible hint why this is happening?
I am reading like this
readFile(cordova.file.applicationDirectory + 'www/json/anomalies.json').then((res) => {
const data = JSON.parse(res)
where readFile is
export function readFile (path, options) {
options = options || {}
return new Promise(function (resolve, reject) {
window.resolveLocalFileSystemURL(path, (fileEntry) => {
fileEntry.file((file) => {
const reader = new FileReader()
reader.onloadend = () => {
resolve(reader.result)
}
const format = options.format
switch (format) {
case 'arrayBuffer':
reader.readAsArrayBuffer(file)
break
case 'binaryString':
reader.readAsBinaryString(file)
break
case 'dataURL':
reader.readAsDataURL(file)
break
default:
reader.readAsText(file)
}
reader.onerror = () => {
reject(Error(`Error occurred reading file: ${path}`))
}
})
}, (error) => {
reject(Error('resolve error', error))
})
})
}

Any help will be highly appreciated Thanks
If it's erroring at the FileReader level, you may not be seeing the result because you're only hooking the onerror callback after the readAs* call.
Otherwise it will be good to include the error, if any.
I don't think it's related, but you resolve during onloadend but also reject in onerror. This is a problem because on error, both will be called and you are going to try to resolve or reject a a promise that already has an resolution. Instead of onloadend, you can use onload instead which will only fire on successful, which should guarantee that you resolve/reject the promise only once.
Otherwise, I don't see any a problem code wise.
Thank you very much @breautek
If it's erroring at the
FileReaderlevel, you may not be seeing the result because you're only hooking theonerrorcallback after thereadAs*call.
Should I then declare the reader.onerror before the readAs* call? Interesting, I will do it
I don't think it's related, but you resolve during
onloadendbut also reject inonerror. This is a problem because on error, both will be called and you are going to try to resolve or reject a a promise that already has an resolution. Instead ofonloadend, you can useonloadinstead which will only fire on successful, which should guarantee that you resolve/reject the promise only once.
Thank you very much, it makes sense, I will amend onloadend to onload
It seems that the discussion has reached a resolution. If the issue has been resolved, could you please close the ticket?
thanks for all the support and great work