Any plugin of ionic v2 to know if I have internet in the network that connects me?

0

Review the documentation and implement this plugin in my app link

When reviewing its functionality, I realize that it only informs you if you connected to a wifi network, 4g or if you are disconnected, BUT when we are "connected to any wifi" and we do not have data or we do not have access to the network. the plugin takes it as true.

This will help me to make saved synchronizations with a local bd when we do not have a connection and when we have a connection, the data is sent and the local bd is cleaned. Suggestions?

code

import { Component } from '@angular/core';
import { NavController, ActionSheetController, ToastController } from 'ionic-angular';
import { Network } from '@ionic-native/network';
import { Subscription} from 'rxjs/Subscription';
import { TranslateService } from '@ngx-translate/core';
import { DataJsonProvider } from '../../providers/data-json/data-json';
import { CalendarComponentOptions } from 'ion2-calendar';
@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})

export class HomePage {
  connected: Subscription;
  disconnected: Subscription;
  Inicio:any;
  tabBarElement: any;
  splash = true;
  idioma:any;



constructor(public navCtrl: NavController ,public actionSheetCtrl: ActionSheetController,
    private toast: ToastController, private network: Network, private translate: TranslateService, ) {  }

ionViewDidEnter() {
    this.connected = this.network.onConnect().subscribe(data => {
      console.log(data)
      this.displayNetworkUpdate(data.type);
    }, error => console.error(error));

    this.disconnected = this.network.onDisconnect().subscribe(data => {
      console.log(data)
      this.displayNetworkUpdate(data.type);
    }, error => console.error(error));
  }

  displayNetworkUpdate(connectionState: string){
    let networkType = this.network.type;
    this.toast.create({
      message: 'You are now ${connectionState}via${networkType},
      duration: 3000
    }).present();
  }

   ionViewDidLoad() {  
    setTimeout(() => {
      this.splash = false; 
    }, 1000);
  }
  ionViewWillLeave(){
    this.connected.unsubscribe();
    this.disconnected.unsubscribe();
  }
}
    
asked by Dannuu Gomez 15.02.2018 в 16:20
source

0 answers