How to use the ionic-native.Network.onConnect function in ionic-native

To help you get started, we’ve selected a few ionic-native examples, based on popular ways it is used in public projects.

github chsakell / ionic2-angular2-firebase / app / app.ts View on Github external
watchForConnection() {
    var self = this;
    let connectSubscription = Network.onConnect().subscribe(() => {
      console.log('network connected!');
      // We just got a connection but we need to wait briefly
      // before we determine the connection type.  Might need to wait
      // prior to doing any api requests as well.
      setTimeout(() => {
        console.log(Network.connection);
        console.log('we got a connection..');
        console.log('Firebase: Go Online..');
        self.dataService.goOnline();
        self.events.publish('network:connected', true);
      }, 3000);
    });
  }
github microsoft / Bing-Maps-Fleet-Tracker / MobileClient / src / pages / home / home.ts View on Github external
ngOnInit() {
      this.connectSub = Network.onConnect().subscribe(() => this.ngZone.run(() => this.connected()));
      this.disconnectSub = Network.onDisconnect().subscribe(() => this.ngZone.run(() => this.disconnected()));

      this.settingsSrvc.get(Settings.BackendUrl).then((val) => {
        if (!val) {
          let registration = this.modalCtrl.create(RegistrationPage);
          registration.onDidDismiss(data => {
            if(!data){
              navigator.app.exitApp();
            }

            Promise.all([
              this.settingsSrvc.set(Settings.BackendUrl, data.baseUrl),
              this.settingsSrvc.set(Settings.SecurityToken, data.deviceToken),
              ]).then(() => {this.continueInitialization();});
          });
          registration.present();
github crabcanon / angular2-ionic2-demo / src / providers / native-service.ts View on Github external
checkNetworkConnection() {
    this.networkConnectSubscription = Network.onConnect().subscribe(() => {
      this.events.publish('native:networkConnect', Network.type);
    }, error => {
      console.log('checkNetworkConnection Error: ', error);
    })
  }
github haoshiyou / haoshiyou-client / lab / haoshiyou / app / pages / tabs / tabs.ts View on Github external
this.platform.ready().then(()=> {
      if (this.platform.is("ios") || this.platform.is("android")) {
        this.logger.debug(`The platform is ios or android, setting up disconnectModal.`);
        this.disconnectModal = Modal.create(DisconnectModal);

        this.onDisconnect = Network.onDisconnect().subscribe(() => {
          this.logger.debug(`Disconnected, show disconnectModal.`);
          this.nav.present(this.disconnectModal, {animate: true});
        });

        this.onConnect = Network.onConnect().subscribe(() => {
          this.logger.debug(`Connected, show disconnectModal.`);
          this.disconnectModal.dismiss();
        });

      }
    });
  }
github microsoft / Bing-Maps-Fleet-Tracker / MobileClient / src / providers / map-host-service.ts View on Github external
initialize(mapElement: HTMLElement) {
    this.isOnline = !this.onDevice || navigator.connection.type !== 'none';
    this.mapElement = mapElement;

    this.connectSub = Network.onConnect().subscribe(() => this.connected());
    this.disconnectSub = Network.onConnect().subscribe(() => this.disconnected());

    if (this.isOnline) {
      this.getMapsKey().then(key => {
        this.createMap(key);
      });
    }
    else {
      this.deferMapsCreation = true;
      this.logger.info('deferring map creation');
    }
  }
github fossasia / open-event-organizer-android / src / app / app.component.ts View on Github external
private handleNetworkChanges() {
    this.initDisconnectSubscription();
    Network.onConnect().subscribe(() => {
      this.initDisconnectSubscription();
      setTimeout(() => {
        this.queueService.processQueue();
      }, 3000);
    });
  }