private static bool IsNetworkAvailable(out NetworkReachabilityFlags flags) { if (defaultRouteReachability == null) { defaultRouteReachability = new MonoTouch.SystemConfiguration.NetworkReachability(new IPAddress(0)); defaultRouteReachability.SetCallback(OnChange); defaultRouteReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault); } if (!defaultRouteReachability.TryGetFlags(out flags)) { return(false); } return(IsReachableWithoutRequiringConnection(flags)); }
public static bool IsAdHocWiFiNetworkAvailable(out NetworkReachabilityFlags flags) { if (adHocWiFiNetworkReachability == null) { adHocWiFiNetworkReachability = new MonoTouch.SystemConfiguration.NetworkReachability(new IPAddress(new byte[] { 169, 254, 0, 0 })); adHocWiFiNetworkReachability.SetCallback(OnChange); adHocWiFiNetworkReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault); } if (!adHocWiFiNetworkReachability.TryGetFlags(out flags)) { return(false); } return(IsReachableWithoutRequiringConnection(flags)); }
// Is the host reachable with the current network configuration public static bool IsHostReachable(string host) { if (host == null || host.Length == 0) { return(false); } using (var r = new MonoTouch.SystemConfiguration.NetworkReachability(host)) { NetworkReachabilityFlags flags; if (r.TryGetFlags(out flags)) { return(IsReachableWithoutRequiringConnection(flags)); } } return(false); }
public static NetworkReachabilityResult RemoteHostStatus() { NetworkReachabilityFlags flags; bool reachable; if (remoteHostReachability == null) { remoteHostReachability = new MonoTouch.SystemConfiguration.NetworkReachability(HostName); // Need to probe before we queue, or we wont get any meaningful values // this only happens when you create NetworkReachability from a hostname reachable = remoteHostReachability.TryGetFlags(out flags); remoteHostReachability.SetCallback(OnChange); remoteHostReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault); } else { reachable = remoteHostReachability.TryGetFlags(out flags); } if (!reachable) { return(NetworkReachabilityResult.NotReachable); } if (!IsReachableWithoutRequiringConnection(flags)) { return(NetworkReachabilityResult.NotReachable); } if ((flags & NetworkReachabilityFlags.IsWWAN) != 0) { return(NetworkReachabilityResult.ReachableViaCarrierDataNetwork); } return(NetworkReachabilityResult.ReachableViaWiFiNetwork); }