how to check the internet before opening an ionic app?

1

I'm developing an app ionic with an iframe . At the moment the app is complete and running, but when accessing the same without internet appears an error message.

I would like to put a message or a screen so that if you have internet access the page where you have iframe , if you do not have an internet show a message.

Could anyone help me with this?

    
asked by anonymous 30.08.2017 / 15:15

1 answer

1

If it's IONIC 2 , see here at documentation about Network on which you need to use the onDisconnect() method to check whether or not you have a connection.

According to the documentation, you basically need to import lib :

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

Below is how you can use the onDisconnect

let connection = this.network.onDisconnect().subscribe(() => {

   // mensagem no console que não possui conexão.
   console.log('Não possui conexão com internet :-(');

  // aqui você insere o layout/iframe/mensagem para exibir para o
  // usuário informando que não possuir conexão com internet
});
    
30.08.2017 / 16:56