0

We have a cordova application, in this cordova application we want to provide a button for the app to go offline.

What is meant by offline is when the user clicks on the button the app thinks that there is no WiFi or cellular data. And any http requests going from the app will not be able to reach the server. This is required for both iOS and Android as well.

Is there any way to make the app think that it is offline?

Also, yes we can use a variable to keep track of network connectivity and not send http requests if the variable is true, however we have no control of http requests being sent by some libraries that are being used. We want the app to genuinely think that it is in offline status (like if data and WiFi is offed then).

Any suggestions are much appreciated also.

Edit:

There seems to be a duplicate question here

Latest update on enabling and disabling mobile data programmatically

However this question is for Android only and this question is for both Android and iOS and the accepted answer seems only for rooted devices which is not an option here, also this is for a Cordova application however not sure that makes much of a difference here though.

MilindaD
  • 7,533
  • 9
  • 43
  • 63
  • Possible duplicate of [Latest update on enabling and disabling mobile data programmatically](https://stackoverflow.com/questions/31120082/latest-update-on-enabling-and-disabling-mobile-data-programmatically) – Murat Karagöz Oct 09 '17 at 14:43
  • This also involves iOS, whereas that question seems to discuss only about Android. Also this is a cordova app though not sure if that would make much of a difference. – MilindaD Oct 09 '17 at 14:47
  • Why are you using libraries over which you have no control and why do you not have control of them? – Barns Oct 09 '17 at 15:53
  • Well for examplepouchdb sends http requests inside it, etc. We do have control over it but we want to give a user the option to go offline when the app is using Guided Mode (where the user can't enable airplane mode) in this case. – MilindaD Oct 09 '17 at 16:11
  • A third party library must be implemented and initialized. While you are toggling the 'WiFi On/Off' couldn't you just suspend third party objects by setting them to 'null' when you don't want them to send anything. Then re-initialize them when you turn the 'WiFi' back on? – Barns Oct 09 '17 at 17:31
  • Yes you are right we can do that, however this item is for testing, this is to test the app on a device which has Guided Mode where the user cant go offline manually through the device. We want to force the user to go to "Offline" to see how the app behaves for testing. – MilindaD Oct 09 '17 at 17:45
  • I feel like you're asking the wrong question... You might rather ask how to prevent pouchDB from sending request if you don't want to, which should definitly be possible. For testing you might look at something like [this](https://stackoverflow.com/questions/16091243/does-chrome-have-a-work-offline-option). – Phonolog Oct 10 '17 at 11:29

0 Answers0