Hi there, I’m currently having an iOS-specific problem where File.readAsText never resolves properly, everything in .then() doesn’t run, not the logs, the variable setting, nor the the function call. This code works fine on android devices to read the file I need to have read. When I give readAsText an error by misspelling the name or getting the path wrong, it does catch it and log the error code and description, but when it tries to read the file that actually exists, it never resolves and doesn’t update the data in the app. The other two File functions I use work fine and log out the fact that the file does, in fact, exist, so I feel like I’m going insane. Can anyone help me with this? Here is the code for reference:
console.log(‘trying to import JSON as plaintext’);
As it happens, there is a problem within the cordova-file plugin that makes certain promises never resolve in iOS without a fix in zone.js. The fix is to put the polyfills.js script tag before the cordova.js script tag in index.html.
I have the same problem on Android. Tried the suggested solution and it didn’t work for me, i.e. still having the same problem. Does anybody have other suggestions how to solve it? Thanks.
Node : v6.10.3
OS : macOS Sierra
Xcode : Xcode 8.3.1 Build version 8E1000a
ios-deploy : 1.9.0
ios-sim : 5.0.13
===
Code example :
// works fine
this.file.checkFile(this.file.dataDirectory, 'file.json').then(_ => {
// Here the promise never resolves
this.file.readAsText(this.file.dataDirectory, 'file.json').then(text => {}).catch(err => {});
})
Node : v6.10.3
OS : macOS Sierra
Xcode : Xcode 8.3.1 Build version 8E1000a
ios-deploy : 1.9.0
ios-sim : 5.0.13
===
Code example :
// works fine
this.file.checkFile(this.file.dataDirectory, 'file.json').then(_ => {
// Here the promise never resolves
this.file.readAsText(this.file.dataDirectory, 'file.json').then(text => {}).catch(err => {});
})
Don’t know if that’s the problem but I always try to have to same version for all the ionic-native import (you’ve got a mix between 3.5, 3.7 and 3.12.1…)
done, still getting no response… I have been researching hours about this, looks like this is an old issue in Github, they always kinda try to close the issue without a well-defined solution, then people come back again with the same problem…
Mmmmh well I use ionic-native 4.12.1 and cordova-plugin-file 4.3.3, both last version, and I still don’t face the problem anymore.
Could you remove node_modules and install them again?
rm -r node_modules
npm install
P.S.: For the record, had to push a new version in store, so I tested manually the part where I use ionic-native/file and everything was working like a charm
You mean ‘@ionic-native/core: 3.12.1’, right? and yeah, the same over here, I’m reading the source code on the repo for references, could be my OS, people are saying that is working for Mac fellas, But got no idea why isn’t it on Linux. Anyway, thanks man
Is not working on Ubuntu, … I just used Cordova’s fileReader in my project, this wrapper is not working, will try to find out why and submit the issue, later… thanks again