Skip to content

Latest commit

 

History

History
43 lines (31 loc) · 942 Bytes

README.md

File metadata and controls

43 lines (31 loc) · 942 Bytes

Ionic Network Reachability

Ionic Network Reachability, it is used for testing network connection.

Ionic Network Reachability

npm install ionic-network-reachability --save

Usage

app.component.ts

import { IonicNetworkReachability } from 'ionic-network-reachability';

export class AppComponent {

    constructor(private reachability: IonicNetworkReachability) {}

    async checkOnline() {
        try {
            const isOnline = await this.reachability.isReachable('url is optional');
            return isOnline;
        } catch(err) {
            
        }
    }

    monitoringOnlineEvents(url: string) {
        this.reachability.onConnect('url is optional').subscribe((value: boolean) => {
            console.log('online :)');
        });
    }

    monitoringOfflineEvents() {
        this.reachability.onDisconnect().subscribe(() => {
            console.log('offline :(')
        });
    }
}