-
Notifications
You must be signed in to change notification settings - Fork 609
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
bug: capacitor network plugin doesn't fire an event after going back online on iOS simulator #40
Comments
I can reproduce on the simulator, but not on real devices, setting as low priority |
Today, I face this problem on android (real device). |
On my case is iOS broken. The native CAPLog prints all network state changes correct! Latest Dependencies:
async ngOnInit() {
this.platform.ready().then(async () => {
// networkStatusChange is never fired
Network.addListener('networkStatusChange', s => console.log('networkStatusChange', s));
// always returns wifi
const status = await Network.getStatus();
console.log('networkStatus', status);
});
} |
Ah, same issues here. The status change does not fire on iOS device. Get status seems to work when the app loads. I'm trying to dynamically load lower or higher quality photos based on the network status. It would also be nice to see if network status is 3G or 4G, so 3G would load low quality and 4G would load standard quality. Is that functionality going to be available at some point? Thanks for all your hard work guys! |
@kevinclarkadstech you can use ionic-native plugin for network instead, it has similar issue on IOS, but you can trigger the updates by toggling your app with any other. |
If using Angular you have to run it in NgZone to see immediate network changes in your app. Here is a working example:
Then simply subscribe to |
Thanks for your reply. Unfortunately I decided to return to Cordova,
because I couldn't run capacitor on iOS. Even Though I like Capacitor more
than Cordova but I think we still can't rely on Capacitor completely.
…On Wed, Aug 26, 2020 at 11:50 AM thoechtl ***@***.***> wrote:
If using Angular you have to run it in NgZone to see immediate network
changes in your app.
Here is a working example:
import { BehaviorSubject, Observable } from 'rxjs';
import { NgZone } from ***@***.***/core';
import { Plugins } from ***@***.***/core';
const { Network } = Plugins;
export class NetworkService {
isOnline$: Observable<boolean>;
private statusSubject = new BehaviorSubject<boolean>(false);
constructor(
private zone: NgZone,
) {
Network.getStatus().then(status => this.statusSubject.next(status.connected));
this.isOnline$ = this.statusSubject.asObservable();
Network.addListener('networkStatusChange', (status) => {
this.zone.run(() => {
this.statusSubject.next(status.connected);
});
});
}
Then simply subscribe to isOnline$ and everthing should work as expected.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<https://github.com/ionic-team/capacitor/issues/2216#issuecomment-680706354>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADGW534X7DG37SHTNKILDL3SCSZS5ANCNFSM4JSW27XQ>
.
--
Hanif Nouhi
|
moving the plugin to capacitor-plugins repo since network plugin has been moved here please, for people having problems with the Android implementation, report a new issue, this one is about iOS. I can still reproduce with the new implementation, but looks like a bug on the simulator more than a bug in the code |
that work for me (src/app/shared/services/network.service.ts):
|
I have issues with this on a regular iOS phone. Is this ever going to be looked into, or is Ionic giving up? |
The output of
|
I have tested the Network plugin with an app on a real iOS device by walking out of and then into WiFi coverage (no SIM in the device so only connectivity via WiFi). The app was either in activated, deactivated or closed state when walking out of and then into coverage, which resulted in a test matrix with nine test cases. When back in coverage I activated the app and checked the status. Seven of the test cases worked but two did not:
So this is still a problem. Unfortunately, I have no code to share but I hope this description helps to narrow down where the problem might be. These failing test cases were the only ones where the app was activated from closed state while the network was disconnected. The disconnected state was picked up by the application but no events seem to have been fired after that. Could there be a bug where the internal event handling is not properly set up when the app is started while the network is disconnected? EDIT: I tried this again, now with the listener running inside NgZone as shown above and now the events are received as they should! I have always regarded NgZone as an important part of Angular's change detection and I don't understand why running a listener to a Capacitor plugin inside NgZone is necessary to make it work. If someone can explain this I would appreciate it :) |
i just added
into capacitor.config.json file and internet connection issue was solved |
Bug Report
Capacitor Version
npx cap doctor
output:Affected Platform(s)
Current Behavior
The plugin doesn't detect the network state changes (see steps to reproduce)
Expected Behavior
The plugin should detect the network state changes correctly
Reproduction Steps
initializeApp
function inapp.component.ts
as followsThe text was updated successfully, but these errors were encountered: