Content-Length: 264711 | pFad | http://github.com/NativeScript/docs-v8/blob/feat/firebase/connectivity.md

98 docs-v8/connectivity.md at feat/firebase · NativeScript/docs-v8 · GitHub
Skip to content

Latest commit

 

History

History
97 lines (80 loc) · 4.85 KB

connectivity.md

File metadata and controls

97 lines (80 loc) · 4.85 KB
title
Connectivity

Connectivity

The connectivity module provides a common abstraction of the functionality responsible for receiving information about the connection type and availability of the network.

Usage

import { Connectivity } from '@nativescript/core'

export function onNavigatedTo(args) {
  const page = args.object

  // Get the current connection type
  const type = Connectivity.getConnectionType()

  switch (type) {
    case Connectivity.connectionType.none:
      console.log('No connection')
      break
    case Connectivity.connectionType.wifi:
      console.log('WiFi connection')
      break
    case Connectivity.connectionType.vpn:
      console.log('VPN connection')
      break
    case Connectivity.connectionType.mobile:
      console.log('Mobile connection')
      break
    case Connectivity.connectionType.ethernet:
      console.log('Ethernet connection')
      break
    case Connectivity.connectionType.bluetooth:
      console.log('Bluetooth connection')
      break
    default:
      break
  }

  // Starts monitoring the network for changes
  Connectivity.startMonitoring(newConnectionType => {
    switch (newConnectionType) {
      case Connectivity.connectionType.none:
        console.log('Connection type changed to none.')
        break
      case Connectivity.connectionType.wifi:
        console.log('Connection type changed to WiFi.')
        break
      case Connectivity.connectionType.vpn:
        console.log('Connection type changed to VPN.')
        break
      case Connectivity.connectionType.mobile:
        console.log('Connection type changed to mobile.')
        break
      case Connectivity.connectionType.ethernet:
        console.log('Connection type changed to ethernet.')
        break
      case Connectivity.connectionType.bluetooth:
        console.log('Connection type changed to bluetooth.')
        break
      default:
        break
    }
  })

  // Stops monitoring the connection
  Connectivity.stopMonitoring()
}

Methods

Name Type Description
getConnectionType number Gets the type of connection. Returns a value from the connectivityModule.connectionType enumeration. To use this method on Android you need to have the android.permission.ACCESS_NETWORK_STATE permission added to the AndroidManifest.xml file.
startMonitoring(connectionTypeChangedCallback: function) void Starts monitoring the connection type.
stopMonitoring void Stops monitoring the connection type.

API References

Name Type
@nativescript/core/connectivity Module
connectionType Enum

Native Component

Android iOS
CONNECTIVITY_SERVICE (android.content.Context) SCNetworkReachability








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/NativeScript/docs-v8/blob/feat/firebase/connectivity.md

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy