How to check the internet before opening an Ionic app?

Asked

Viewed 926 times

1

I’m developing a app Ionic with a iframe. To date the app is complete and running, but when access the same without internet appears an error message.

I would like to place a message or a screen so that if you have internet access the page where you have the iframe, if you don’t have internet show a message.

Could someone help me with this?

  • IONIC 1 or 2?...

1 answer

1

If it is IONIC 2, see here on own documentation about Network in which you need to use the method onDisconnect() to check whether or not it has a connection.

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

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

Below follows how you can use the method 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
});
  • It shouldn’t be in the onConnect()?

  • @ramaral actually gives almost same thing. If you have disconnected it is because it is not connected! haha

  • I do not know, I do not know the Ionic. However, usually to be onDisconected there must have been a successful connection. If the connection has not been achieved there will be onDisconected.

  • yes, but I have to create a service or I can put it in home.ts, because iframe loads in home.html and I wanted to show a message instead of the error, if there is no connection

Browser other questions tagged

You are not signed in. Login or sign up in order to post.