【问题标题】:Xamarin.Mac - Network connected / disconnected eventXamarin.Mac - 网络连接/断开事件
【发布时间】:2018-11-13 20:17:52
【问题描述】:

如何在 Xamarin.Mac 应用中检测互联网连接?当 LAN 电缆插入/拔出、WIFI 连接/断开或连接到其他可用网络时,我如何接收事件

我的应用程序只能在内部网络上运行,我需要显示在线/离线状态,即在公司网络上时在线,不在公司网络时离线或没有互联网连接。

【问题讨论】:

标签: c# cocoa xamarin xamarin.mac


【解决方案1】:

想出下面来帮助满足我的需要

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.
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-27
    • 1970-01-01
    相关资源
    最近更新 更多