Essential Kit Tutorials
DocumentationDownload
Version 2
Version 2
  • Introduction
  • Features
  • Version 2 vs Version 1
  • Release Notes
    • ✅Version 2.7.4
    • Version 2.7.3
    • Version 2.7.2
    • Version 2.7.1
    • Version 2.7.0
    • Older Versions
      • Version 2.6.1
      • Version 2.6.0
      • Version 2.5.1
      • Version 2.5.0
      • Version 2.4.1
      • Version 2.4.0
      • Version 2.3.1
      • Version 2.3.0
      • Version 2.2.1
      • Version 2.2.0
      • Version 2.1.1
      • Version 2.1.0
      • Version 2.0.4
      • Version 2.0.3
      • Version 2.0.2
      • Version 2.0.1
      • Version 2.0.0
  • Plugin Overview
    • Settings
    • Folder Structure
    • Installation FAQ
    • Localisation
  • Address Book
    • Overview
    • Use Cases
    • Setup
    • Usage
    • Testing
    • FAQ
  • Billing Services
    • Overview
    • Use Cases
    • Setup
      • iOS
      • Android
    • Usage
    • Testing
      • iOS
      • Android
    • FAQ
  • Cloud Services
    • Overview
    • Use Cases
    • Setup
      • iOS
      • Android
    • Usage
    • Testing
    • FAQ
  • Deep Link Services
    • Overview
    • Use Cases
    • Setup
      • iOS
      • Android
    • Usage
    • Testing
    • FAQ
  • Extras (Utilities)
    • Overview
    • Usage
  • Game Services
    • Overview
    • Use Cases
    • Setup
      • iOS
      • Android
    • Usage
    • FAQ
  • Media Services
    • Overview
    • Use Cases
    • Setup
    • Usage
    • FAQ
  • Native UI
    • Overview
    • Use Cases
    • Setup
    • Usage
    • FAQ
  • Network Services
    • Overview
    • Use Cases
    • Setup
    • Usage
    • FAQ
  • Notification Services
    • Overview
    • Use Cases
    • Setup
      • iOS
      • Android
    • Usage
    • FAQ
  • Rate My App
    • Overview
    • Use Cases
    • Setup
    • Usage
    • FAQ
  • Sharing
    • Overview
    • Use Cases
    • Setup
    • Usage
      • Message Composer
      • Mail Composer
      • Social Share Composer
      • Share Sheet
    • FAQ
  • Web View
    • Overview
    • Use Cases
    • Setup
    • Usage
    • FAQ
  • Notes
    • Resolving Android Gradle Build Errors
    • Google Play Services Authentication
Powered by GitBook
On this page
  • Start detecting the status
  • Stop detecting the status
  • Checking status any time

Was this helpful?

Edit on GitHub
  1. Network Services

Usage

PreviousSetupNextFAQ

Last updated 3 years ago

Was this helpful?

Once you set up the details in , you need to import the namespace for starting the network status detection.

using VoxelBusters.CoreLibrary;
using VoxelBusters.EssentialKit;

For detecting the network status you need to start the notifier. Once there is a change in network status, events are fired to capture the status. You need to register for the events first to get the network status.

private void OnEnable()
{
    // register for events
    NetworkServices.OnHostReachabilityChange        += OnHostReachabilityChange;
    NetworkServices.OnInternetConnectivityChange    += OnInternetConnectivityChange;
}

private void OnDisable()
{
    // unregister from events
    NetworkServices.OnHostReachabilityChange        -= OnHostReachabilityChange;
    NetworkServices.OnInternetConnectivityChange    -= OnInternetConnectivityChange;
}
private void OnInternetConnectivityChange(NetworkServicesInternetConnectivityStatusChangeResult result)
{
    Debug.Log("Received internet connectivity changed event.");
    Debug.Log("Internet connectivity status: " + result.IsConnected);
}

private void OnHostReachabilityChange(NetworkServicesHostReachabilityStatusChangeResult result)
{
    Debug.Log("Received host reachability changed event.");
    Debug.Log("Host reachability status: " + result.IsReachable);
}

Start detecting the status

Start the network notifier to enable detection of network connectivity and receive the events.

NetworkServices.StartNotifier();

Stop detecting the status

Once you are done with your requirement on detecting network connectivity, you can stop the notifier by calling StopNotifier.

NetworkServices.StopNotifier();

Checking status any time

Once after you called StartNotifier, there are options to check the status of the network by some utility methods.

bool isInternetActive = NetworkServices.IsInternetActive;
bool isHostReachable = NetworkServices.IsHostReachable;
bool isNotifierActive    = NetworkServices.IsNotifierActive;

It's always good to stop the network notifier if you aren't using the status. This helps to save some network data and device battery for users as the plugin don't need to pool the servers.

As you can see, you can either listen to general internet connectivity or to a specific host. You need to set the host in the Host address section of .

Essential Kit Settings
settings properties