/// <summary>
        /// The remote host status.
        /// </summary>
        /// <param name="hostName">The host name.</param>
        /// <returns>The <see cref="NetworkStatus" />.</returns>
        public static NetworkStatus RemoteHostStatus(string hostName)
        {
            NetworkReachabilityFlags flags;
            bool reachable;

            if (remoteHostReachability == null)
            {
                remoteHostReachability = new 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(NetworkStatus.NotReachable);
            }

            if (!IsReachableWithoutRequiringConnection(flags))
            {
                return(NetworkStatus.NotReachable);
            }

            return((flags & NetworkReachabilityFlags.IsWWAN) != 0
                                       ? NetworkStatus.ReachableViaCarrierDataNetwork
                                       : NetworkStatus.ReachableViaWiFiNetwork);
        }
示例#2
0
 static bool IsNetworkAvailable(out NetworkReachabilityFlags flags)
 {
     if (defaultRouteReachability == null)
     {
         defaultRouteReachability = new NetworkReachability(new IPAddress(0));
         defaultRouteReachability.SetCallback(OnChange);
         defaultRouteReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault);
     }
     return(defaultRouteReachability.TryGetFlags(out flags) && IsReachableWithoutRequiringConnection(flags));
 }
示例#3
0
		static bool IsNetworkAvaialable (out NetworkReachabilityFlags flags)
		{
			if (defaultRouteReachability == null){
				defaultRouteReachability = new NetworkReachability (new IPAddress (0));
				defaultRouteReachability.SetCallback (OnChange);
				defaultRouteReachability.Schedule (CFRunLoop.Current, CFRunLoop.ModeDefault);
			}
			if (defaultRouteReachability.TryGetFlags (out flags))
			    return false;
			return IsReachableWithoutRequiringConnection (flags);
		}	
示例#4
0
		public static bool IsAdHocWiFiNetworkAvailable (out NetworkReachabilityFlags flags)
		{
			if (adHocWiFiNetworkReachability == null){
				adHocWiFiNetworkReachability = new 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);
		}
 private static bool IsNetworkAvaialable(out NetworkReachabilityFlags flags)
 {
     if (defaultRouteReachability == null)
     {
         defaultRouteReachability = new NetworkReachability(new IPAddress(0));
                         #warning Need to look at SetNotification instead - ios6 change
         defaultRouteReachability.SetCallback(OnChange);
         defaultRouteReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault);
     }
     if (defaultRouteReachability.TryGetFlags(out flags))
     {
         return(false);
     }
     return(IsReachableWithoutRequiringConnection(flags));
 }
示例#6
0
        public static bool IsAdHocWiFiNetworkAvailable(out NetworkReachabilityFlags flags)
        {
            if (adHocWiFiNetworkReachability == null)
            {
                adHocWiFiNetworkReachability = new 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));
        }
示例#7
0
    public override bool FinishedLaunching(UIApplication app, NSDictionary options)
    {
        imageCarrier = UIImage.FromFile ("WWAN5.png");
        imageWiFi = UIImage.FromFile ("Airport.png");
        imageStop = UIImage.FromFile ("stop-32.png");

        nr = new NetworkReachability ("www.apple.com");
        nr.SetCallback (ReachabilityChanged);
        nr.Schedule (CFRunLoop.Current, CFRunLoop.ModeDefault);

        AddTable ();
        //UpdateStatus ();
        //UpdateCarrierWarning ();

        window.MakeKeyAndVisible ();

        return true;
    }
示例#8
0
    public override bool FinishedLaunching(UIApplication app, NSDictionary options)
    {
        imageCarrier = UIImage.FromFile("WWAN5.png");
        imageWiFi    = UIImage.FromFile("Airport.png");
        imageStop    = UIImage.FromFile("stop-32.png");

        nr = new NetworkReachability("www.apple.com");
        nr.SetCallback(ReachabilityChanged);
        nr.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault);

        AddTable();
        //UpdateStatus ();
        //UpdateCarrierWarning ();

        window.MakeKeyAndVisible();

        return(true);
    }
示例#9
0
    public static NetworkStatus RemoteHostStatus()
    {
        NetworkReachabilityFlags flags;
        bool reachable;

        if (remoteHostReachability == null)
        {
            remoteHostReachability = new NetworkReachability(HostName);

            reachable = remoteHostReachability.TryGetFlags(out flags);

            remoteHostReachability.SetCallback(OnChange);
            remoteHostReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault);
        }
        else
        {
            reachable = remoteHostReachability.TryGetFlags(out flags);
        }

        if (!reachable)
        {
            return(NetworkStatus.NotReachable);
        }

        if (!IsReachableWithoutRequiringConnection(flags))
        {
            return(NetworkStatus.NotReachable);
        }

        if ((flags & NetworkReachabilityFlags.IsWWAN) != 0)
        {
            return(NetworkStatus.ReachableViaCarrierDataNetwork);
        }

        return(NetworkStatus.ReachableViaWiFiNetwork);
    }
        public static NetworkStatus RemoteHostStatus(string HostName)
        {
            NetworkReachabilityFlags flags;
            bool reachable;

            if (remoteHostReachability == null) {
                remoteHostReachability = new 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 NetworkStatus.NotReachable;

            if (!IsReachableWithoutRequiringConnection (flags))
                return NetworkStatus.NotReachable;

            if ((flags & NetworkReachabilityFlags.IsWWAN) != 0)
                return NetworkStatus.ReachableViaCarrierDataNetwork;

            return NetworkStatus.ReachableViaWiFiNetwork;
        }
示例#11
0
    public static NetworkStatus RemoteHostStatus()
    {
        NetworkReachabilityFlags flags;
        bool reachable;

        if (remoteHostReachability == null)
        {
            remoteHostReachability = new NetworkReachability (HostName);

            reachable = remoteHostReachability.TryGetFlags (out flags);

            remoteHostReachability.SetCallback (OnChange);
            remoteHostReachability.Schedule (CFRunLoop.Current, CFRunLoop.ModeDefault);
        }
        else
            reachable = remoteHostReachability.TryGetFlags (out flags);

        if (!reachable)
            return NetworkStatus.NotReachable;

        if (!IsReachableWithoutRequiringConnection (flags))
            return NetworkStatus.NotReachable;

        if ((flags & NetworkReachabilityFlags.IsWWAN) != 0)
            return NetworkStatus.ReachableViaCarrierDataNetwork;

        return NetworkStatus.ReachableViaWiFiNetwork;
    }
示例#12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Reachability.Reachability"/> class.
 /// </summary>
 /// <param name='reachability'>
 /// NetworkReachability instance to use
 /// </param>
 /// <param name='hasWWAN'>
 /// Platform has a WWAN interface
 /// </param>
 protected Reachability(NetworkReachability reachability, bool hasWWAN)
 {
     NetworkReachability = reachability;
     HasWWAN = hasWWAN;
     AllowWWAN = true;
     NetworkReachability.SetCallback(OnReachabilityNotification);
     NetworkReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault);
 }