# Check connection if offline doesn't show Toast

**URL:** <https://forum.ionicframework.com/t/check-connection-if-offline-doesnt-show-toast/161945>\
**Category:** Ionic Framework\
**Created:** [April 18, 2019, 10:15am UTC](https://forum.ionicframework.com/t/check-connection-if-offline-doesnt-show-toast/161945 "2019-04-18T10:15:12Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![ianrush](https://avatars.discourse-cdn.com/v4/letter/i/57b2e6/32.png) [@ianrush](https://forum.ionicframework.com/u/ianrush)\
**Post date:** [April 18, 2019, 10:15am UTC](https://forum.ionicframework.com/t/check-connection-if-offline-doesnt-show-toast/161945/1 "2019-04-18T10:15:12Z")

</div>

![Capture](https://global.discourse-cdn.com/ionicframework/original/3X/6/8/68b6b4ccbe27f87a9476ad26562597ffa9e3ff7c.jpeg) ![Capture1](https://global.discourse-cdn.com/ionicframework/original/3X/f/7/f78f539e7be148f51ca7cab95532864da8f687af.jpeg)

I want to show toast alert when disconnected but it just showed the alert above, please tell me how to fix it. Thanks guys,

---

<div class="post-metadata">

**Author:** ![aharonDLis](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@aharonDLis](https://forum.ionicframework.com/u/aharonDLis)\
**Post date:** [April 18, 2019, 10:24am UTC](https://forum.ionicframework.com/t/check-connection-if-offline-doesnt-show-toast/161945/2 "2019-04-18T10:24:22Z")

</div>

Does adding an await keyword to your method call help?

```auto
this.event.subscribe('network:offline', async () => {
...
...
await this.networkAlrert();

```

---

<div class="post-metadata">

**Author:** ![ianrush](https://avatars.discourse-cdn.com/v4/letter/i/57b2e6/32.png) [@ianrush](https://forum.ionicframework.com/u/ianrush)\
**Post date:** [April 19, 2019, 3:16am UTC](https://forum.ionicframework.com/t/check-connection-if-offline-doesnt-show-toast/161945/3 "2019-04-19T03:16:22Z")

</div>

Tks u, I tried it but it still doesn’t work. Do you have any idea else ?

---

<div class="post-metadata">

**Author:** ![gokujy](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/gokujy/32/117753_2.png) [@gokujy](https://forum.ionicframework.com/u/gokujy)\
**Post date:** [April 19, 2019, 5:04am UTC](https://forum.ionicframework.com/t/check-connection-if-offline-doesnt-show-toast/161945/4 "2019-04-19T05:04:42Z")

</div>

Hello,  
Import the Network in app.module.ts file

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

```

add the network in provider

```auto
providers: [Network]

```

now open an app.component.ts file and import the Network and ToastController

```auto
import { Network } from '@ionic-native/network/ngx';
import { ToastController } from '@ionic/angular';

constructor(private network: Network, public toastController: ToastController) { }

  initializeApp() {
  this.platform.ready().then(() => {
    // watch network for a disconnection
    let disconnectSubscription = this.network.onDisconnect().subscribe(() => {
      alert('network was disconnected :-(');
       const toast = await this.toastController.create({
        message: 'You are appear to be offline. Please try again!.',
        showCloseButton: true
      });
      toast.present();
    });
    // watch network for a connection
    let connectSubscription = this.network.onConnect().subscribe(() => {
      alert('network connected!');
    });
    this.statusBar.styleDefault();
    this.splashScreen.hide();
  });
}

```

OR

you just want show alert, try to put your toast code after this.splash = true;.  
Hope that help you 🙂

---

<div class="post-metadata">

**Author:** ![ianrush](https://avatars.discourse-cdn.com/v4/letter/i/57b2e6/32.png) [@ianrush](https://forum.ionicframework.com/u/ianrush)\
**Post date:** [April 19, 2019, 6:37am UTC](https://forum.ionicframework.com/t/check-connection-if-offline-doesnt-show-toast/161945/5 "2019-04-19T06:37:42Z")

</div>

Tks u but it still doesn’t work. It just show the alert ‘network was disconnected :-(’  
I’ve tried Ionic Native Dialogs and Toast and both worked. But neither ToastController nor AlertController work as it expected, I don’t know why 🙄

> **[Ionic Documentation](https://ionicframework.com/docs/native/toast)**
>
> Ionic is the app platform for web developers. Build amazing mobile, web, and desktop apps all with one shared code base and open web standards

---

<div class="post-metadata">

**Author:** ![gokujy](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/gokujy/32/117753_2.png) [@gokujy](https://forum.ionicframework.com/u/gokujy)\
**Post date:** [April 19, 2019, 9:22am UTC](https://forum.ionicframework.com/t/check-connection-if-offline-doesnt-show-toast/161945/6 "2019-04-19T09:22:13Z")

</div>

Hello, just use my code and it’s working perfect in my app and don’t use plugin for toast. use this component for [toast](https://ionicframework.com/docs/api/toast-controller)

 ![44fa7af6-571d-4ee5-92ac-df92bb8392e8](https://global.discourse-cdn.com/ionicframework/original/3X/e/8/e8133a72a41f9dddb11698b0a4656f88771e15a3.jpeg)

---

<div class="post-metadata">

**Author:** ![ianrush](https://avatars.discourse-cdn.com/v4/letter/i/57b2e6/32.png) [@ianrush](https://forum.ionicframework.com/u/ianrush)\
**Post date:** [April 26, 2019, 7:42am UTC](https://forum.ionicframework.com/t/check-connection-if-offline-doesnt-show-toast/161945/7 "2019-04-26T07:42:47Z")

</div>

It worked well in Android but just worked only at first time with onDisconnect on IOS (tested with Simulator). Maybe a problem with IOS ?

---

<div class="post-metadata">

**Author:** ![vivek-23](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/vivek-23/32/125332_2.png) [@vivek-23](https://forum.ionicframework.com/u/vivek-23)\
**Post date:** [April 26, 2019, 9:15am UTC](https://forum.ionicframework.com/t/check-connection-if-offline-doesnt-show-toast/161945/8 "2019-04-26T09:15:28Z")

</div>

Should work without issues. By the way, why do you need `await` in `await toast.present();` ?

---

<div class="post-metadata">

**Author:** ![Lakshmareddy](https://avatars.discourse-cdn.com/v4/letter/l/ea666f/32.png) [@Lakshmareddy](https://forum.ionicframework.com/u/Lakshmareddy)\
**Post date:** [April 26, 2019, 10:17am UTC](https://forum.ionicframework.com/t/check-connection-if-offline-doesnt-show-toast/161945/9 "2019-04-26T10:17:40Z")

</div>

use the navigator. It Works perfectly…

if(navigator.onLine)  
{  
this.isconnected=true

```
} else{
  this.isconnected=false
}
```

---

<div class="post-metadata">

**Author:** ![bspc](https://avatars.discourse-cdn.com/v4/letter/b/b9e5f3/32.png) [@bspc](https://forum.ionicframework.com/u/bspc)\
**Post date:** [May 16, 2019, 5:24pm UTC](https://forum.ionicframework.com/t/check-connection-if-offline-doesnt-show-toast/161945/10 "2019-05-16T17:24:53Z")

</div>

I’m having a similar issues with Toasts in Ionic 4+. I found this bug report that describes the issue in more detail. Apparently, the ToastController (and other controllers) can fail when the device is offline due to lazy loading.

Sadly, I don’t have a workaround for using toasts when offline yet.

> <https://github.com/ionic-team/ionic/issues/17450>

---

<div class="post-metadata">

**Author:** ![saifk](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/saifk/32/127797_2.png) [@saifk](https://forum.ionicframework.com/u/saifk)\
**Post date:** [November 29, 2019, 7:11am UTC](https://forum.ionicframework.com/t/check-connection-if-offline-doesnt-show-toast/161945/11 "2019-11-29T07:11:26Z")

</div>

```auto
if (this.network.type == 'none' ) {
     this.toastCtrl.create ({
     message: 'Check your Network connection.Please check your wifi or mobile data',
     duration: 3000,
    }).present();
    } else {
   console.log('Internet Connection is live')
  }

```
