Configuring the whitelist
Because we'll be sending and receiving data over the network connection, we need to configure the network whitelist. Typically, Cordova's sample applications allow communication with any host. But generally, you should actively restrict the hosts your app can communicate with unless you have very good reasons for permitting unrestricted communication (for example, your app is a browser).
The first thing you need is the whitelist plugin. To add it using the Cordova CLI, you can do as follows:
cordova plugin add cordova-plugin-whitelist
On the other hand, since we're handling plugins in our app's package.json
, we can add it to the plugins
section, as follows:
..., "plugins": { ..., "cordova-plugin-whitelist" }, ...
Once this is done, we can run gulp init
to rebuild the Cordova project with the necessary plugins.
Tip
As of version 4.0 of the Cordova iOS and Cordova Android, all network access is denied unless the whitelist plugin is added. This is a breaking change...