Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. import { Injectable } from '@angular/core';
  2. import { Network } from '@ionic-native/network';
  3. import { Subscription } from 'rxjs/Subscription';
  4.  
  5. @Injectable()
  6. export class NetworkProvider {
  7.  
  8. connect: Subscription;
  9. disconnect: Subscription;
  10.  
  11. constructor(private _network: Network) { }
  12.  
  13. watchDisconect() {
  14. this.disconnect = this._network.onDisconnect().subscribe(data => {
  15. console.log('network was disconnected :-(');
  16. });
  17.  
  18. this.disconnect.unsubscribe();
  19. }
  20.  
  21. watchConect() {
  22. this.connect = this._network.onConnect().subscribe(data => {
  23. console.log('network connected!');
  24.  
  25. setTimeout(() => {
  26. if (this._network.type === 'wifi') {
  27. console.log('we got a wifi connection, woohoo!');
  28. }
  29. }, 3000);
  30.  
  31. });
  32.  
  33. this.connect.unsubscribe();
  34. }
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement