Usage

Once you set up the details in Essential Kit Settings, 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.

Stop detecting the status

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

Checking status any time

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

Last updated

Was this helpful?