Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Online event not firing on iOS or Android #79

Open
JoeOsterfeld opened this issue Dec 4, 2018 · 3 comments
Open

Online event not firing on iOS or Android #79

JoeOsterfeld opened this issue Dec 4, 2018 · 3 comments

Comments

@JoeOsterfeld
Copy link

Steps to repeat:

  1. Create a Cordova/Ionic app.
  2. Listen for onConnect events:
document.addEventListener('online', onOnline, false);
function onOnline() {
    // This never fires
    console.log('I\'m online!');
}
Cordova:

   cordova (Cordova CLI) : 8.1.2 ([email protected])
   Cordova Platforms     : android 7.1.2, ios 4.5.5
   Cordova Plugins       : cordova-plugin-ionic-keyboard 2.1.2, cordova-plugin-ionic-webview 2.1.4, (and 14 other plugins)

System:
   Android SDK Tools : 26.1.1 (/Users/username/Library/Android/sdk)
   ios-deploy        : 1.9.4
   ios-sim           : 7.0.0
   NodeJS            : v10.13.0 (/Users/username/.nvm/versions/node/v10.13.0/bin/node)
   npm               : 6.4.1
   OS                : macOS High Sierra
   Xcode             : Xcode 10.1 Build version 10B61
@PieterVanPoyer
Copy link
Contributor

PieterVanPoyer commented Dec 22, 2018

Hey, I've tested it on Android.

If you run an Ionic app, the 'online' event is normally added after the deviceready (platform.ready()) event. The 'online' or 'offline' event is already fired then. (The first events are fired even before the first deviceready event on android);

You could always read the type of navigator.connection when you need to:

const networkState = navigator.connection.type;

if (networkState === 'none') {
   console.log('We are offline');
} else {
   console.log('We are online');
}

In our company, we allways check the navigator.connection.type before every api call.

If you need more help attach your project.

Kind regards,
Pieter

@anaaChacon
Copy link

anaaChacon commented Jan 14, 2019

the solution that it poses @PieterVanPoyer has solved the problem for me pm android, but in them there is iOS no solution, at the moment I am satisfied.

@TeChn4K
Copy link

TeChn4K commented May 13, 2019

Any update on this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants
@janpio @TeChn4K @anaaChacon @JoeOsterfeld @PieterVanPoyer and others