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 fires every time app resumes from background (iOS and Android) #91

Closed
3 tasks done
EvelinJK opened this issue Aug 19, 2019 · 21 comments
Closed
3 tasks done

Comments

@EvelinJK
Copy link

Bug Report

Problem

The online event fires unreliably when an app moves from background to foreground.
This occurs on iOS AND Android for us.
It might be related to #82 but it is definitely not resolved with 2.0.2

What is expected to happen?

Online event only fires when network connection was lost and is established again.

What does actually happen?

Online event fires every time the app was in background and comes to foreground again, even though wifi is connected at all times.

Information

We show a message to the user when he goes offline, and one when he goes online again, so we rely on the event listeners.

Offline works fine, but the online event fires every time the App comes from background to foreground although wifi is connected at all times.

The connection seems to go to `type: none' when the App goes to background, which makes the online event fire when the app comes to foreground again.

We pretty much use the code as in the Cordova documentation, so there's no special implementation that could affect the behavior.

Environment, Platform, Device

Tested on iOS (12.4) and Android (9 and 6.0.1)

Version information

React
cordova 9.0.0

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above
@EvelinJK EvelinJK changed the title Online event fires every time app resumes from background Online event fires every time app resumes from background (iOS and Android) Aug 19, 2019
@nero120
Copy link

nero120 commented Aug 25, 2019

I'm also experiencing this issue, using cordova-plugin-network-information 2.0.2 and cordova-android 8.0.0, on an Android 8 device.

@ColDrekken
Copy link

Same on my side. On Android it also fired when using Camera from app for some stuff. At the moment im finished with Kamera and close it its like a app resume, which is normaly ok, but i dont see the reason to re-detect network then.

@jake-moritz-trifecta
Copy link

Is this plugin still maintained? I'm also seeing this issue on plugin version 2.0.2 and cordova-android 8.0.0.

@paulovargatt
Copy link

I controlled this problem by using a variable

  disconnectSubscription() {
       this.net.onDisconnect().subscribe(() => {
           this.pageActive = window.location.pathname;
           this.desconect = true;
           return this.nav.navigateForward('app/tabs/network');
       });
   }

   connectSubscription() {
       this.net.onConnect().subscribe(() => {
           if (this.desconect) {
               this.desconect = false;
               return this.nav.navigateRoot(this.pageActive ? this.pageActive : 'app/tabs/home');
           }
       });
   }

@ipehimanshu
Copy link

yes i have same issue for android 6.3.0 so downgrade to old version.

@brassier
Copy link

I'm seeing the same on at least 2 Android devices (Android 7 and Android 9), using cordova-android 8.1.0. Downgrading to 2.0.1 of this plugin resolved it, although that's obviously not the desired approach.

@EinfachHans
Copy link

same Issue here. Downgrading to 2.0.1 worked for me. Cam someone please fix this? @janpio

@tryhardest
Copy link

Anyone able to push a fix?

@EinfachHans
Copy link

@tryhardest downgrade to 2.0.1

@tryhardest
Copy link

why downgrade at @HansKrywaa @brassier @ipehimanshu did you try yet @paulovargatt variable above? Will downgrade if needs be yes but I will try with the variable first. Would be nice to get a fix.

@breautek
Copy link
Contributor

For android, this seems to be a problem with the Connectivitymanager.getActiveNetworkInfo() with certain conditions being met on the device, one of which is the app going into the background.

Haven't experimented this myself, but this is what an stackoverflow answer suggests.

Good news is that this API is deprecated, and there is supposedly a better way of obtaining connection info, using the NetworkCallback API.

Bad news is, this API is only available as of API level 21 (Android 5.0) , so it will require a major update and will have to wait until android 4.4 is dropped completely. Android 4.4 will likely be dropped in cordova-android 9, but that is still work-in-progress. If the NetworkCallback API is indeed more consistent and reliable, it won't make it into master until we are ready to prepare a major release, and that release will only happen sometime after cordova-android 9 is release (assuming cordova-android 9 indeed drops support for android 4.4 (API level 19 & 20). PRs are still welcome, even if they need to wait for a major update cycle.

Not experienced enough with iOS to comment on that side of this issue.

@Shals08
Copy link

Shals08 commented Jul 17, 2020

Any update on this issue?
Even am facing the same issue Online/offline event fires every time app resumes from background (iOS and Android)

@breautek
Copy link
Contributor

breautek commented Jul 17, 2020

Any update on this issue?
Even am facing the same issue Online/offline event fires every time app resumes from background (iOS and Android)

This issue may actually have been fixed by #114 but that hasn't been released yet.

You can test it out on using the nightly version. Do note that nightly versions aren't recommended for production use however.

@ipehimanshu
Copy link

is it still resolved or not ?
any news ?

@breautek
Copy link
Contributor

is it still resolved or not ?
any news ?

This may be fixed by #114

You can confirm if the issue still persists by using the nightly version of this plugin. If you can confirm, please let me know and I can close this issue.

@ipehimanshu
Copy link

@breautek sir
nightly version means from git latest version or can you provide me command to download that?
Thanks in advance

@breautek
Copy link
Contributor

Well I was going to suggest nightly, but it appears this plugin on npm is missing the nightly tag for some reason 😕

But yes, using git should also do the trick:

cordova plugin add https://github.com/apache/cordova-plugin-network-information.git#master

@ipehimanshu
Copy link

ok sir
thanks for sharing, i will check and let you know

@ipehimanshu
Copy link

@breautek
i confirm that latest master version of this git is solved this issue.
Git solved version : 3.0.0-dev
Thanks

@breautek
Copy link
Contributor

Thanks for confirming. This means on the next release the fix will be available for production use. Unfortunately I can't provide any ETA on this will be.

@brassier
Copy link

@breautek - can you speak to any release plans for this issue? Thank you!

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

No branches or pull requests