Unable to get network connection after switching from wifi to cellular data

Hi folks

We’re facing the problem that we (sometimes) lose internet connection after entering or leaving our wifi and changing from/to cellular data. After that we’re unable to retrieve any data from a web api.

The following code shows how we handle network changes:

import { Network } from '@ionic-native/network';

export enum ConnectionStatus {
    Online,
    Offline
}

@Injectable()
export class NetworkHelper {

    private status: BehaviorSubject<ConnectionStatus> = new BehaviorSubject(ConnectionStatus.Offline);

    constructor(public network: Network, public eventCtrl: Events) { 
        this.initializeNetworkEvents();
    }

    public initializeNetworkEvents() {
        this.network.onDisconnect().subscribe(() => {
            if (this.status.getValue() === ConnectionStatus.Online) {
                console.log('WE ARE OFFLINE');
                this.eventCtrl.publish('network:offline');
            }
        });

        this.network.onConnect().subscribe(() => {
            if (this.status.getValue() === ConnectionStatus.Offline) {
                console.log('WE ARE ONLINE');
                this.eventCtrl.publish('network:online');
            }
        });
    }
}

The only way so far to recover is to either turn on and off flight mode or restart the app manually. This of course is not acceptable for the user.

Did anybody face the same issue and knows how to solve it?

Thanks and best regards
Timon

Hi, we are facing the same issue. Have you solved it?

Hi

Unfortunately we were not able to solve it. A workaround we implemented is that if we detect a network change while the
app is in background we just kill the app. This really is a dirty hack and not even covers all scenarios.

We did not investigate the issue under Ionic 4 and have some hope that it is fixed there…

So on the bottom line we’re also still looking for a solution!

Cheers