0
votes

How can I detect the internet connectivity in a Xamarin.Mac app? How can I receive an event when LAN cable is plugged / unplugged, WIFI connected / disconnected or connected to other available networks?

My application can only run on an internal network and I need to show the online / offline status i.e. online when on company network, offline when not on company network or no internet connection.

1
Refer here @Cheesebaron answer stackoverflow.com/questions/52200514/…R15

1 Answers

0
votes

Figured out below to help suffice my need

NetworkReachability _defaultRouteReachability;
public override void WindowDidLoad()
{
   if (_defaultRouteReachability == null)
   {
      _defaultRouteReachability = new NetworkReachability("https://example.com");
      _defaultRouteReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault);
      _defaultRouteReachability.SetNotification(HandleNotification);
   }
}

void HandleNotification(NetworkReachabilityFlags flags)
{
   //Handle your actions here.
}