Essential Kit Tutorials
DocumentationDownload
Latest(v3)
Latest(v3)
  • Introduction
  • Features Overview
  • Whats new in v3
    • Version 3 vs Version 2
    • Release Notes
    • Upgrade from V2
  • Plugin Overview
    • Settings
    • Folder Structure
    • Installation FAQ
    • Upgrade Guide
  • Features
    • 📒Address Book
      • Setup
      • Usage
      • Testing
      • FAQ
    • App Shortcuts
      • Setup
      • Usage
    • 🆕App Updater
      • Setup
      • Usage
    • 💲Billing Services
      • Setup
        • iOS
        • Android
      • Usage
      • Testing
        • iOS
        • Android
      • FAQ
    • ☁️Cloud Services
      • Setup
        • iOS
        • Android
      • Usage
      • Testing
      • FAQ
    • 🔗Deep Link Services
      • Setup
        • iOS
        • Android
      • Usage
      • Testing
      • FAQ
    • 🛠️Utilities (Extras)
      • Usage
    • 💯Game Services
      • Setup
        • iOS
        • Android
      • Usage
      • FAQ
    • 📸Media Services
      • Setup
      • Usage
      • FAQ
    • 📆Native UI
      • Setup
      • Usage
      • FAQ
      • Examples
        • Login Dialog
    • Network Services
      • Setup
      • Usage
      • FAQ
    • ⏰Notification Services
      • Setup
        • iOS
        • Android
      • Usage
      • Examples
        • Nudge to come-back to the game
      • FAQ
    • ⭐Rate My App
      • Setup
      • Usage
      • FAQ
    • 🤝Sharing
      • Setup
      • Usage
        • Message Composer
        • Mail Composer
        • Social Share Composer
        • Share Sheet
      • FAQ
      • Examples
        • Add Attachment Example
    • Task Services
      • Setup
      • Usage
    • 🌏Web View
      • Setup
      • Usage
      • FAQ
      • Examples
        • Loading Pdf File
  • Notes
    • Resolving Android Gradle Build Errors
    • Google Play Services Authentication
    • Target API Level vs Min API Level
    • Handling Refunds for In-App Purchases (Billing Services)
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. Features
  2. Network Services

Usage

PreviousSetupNextFAQ

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