예제 #1
0
 void Disconnect()
        {
            Console.WriteLine("Dongle connected closed");
        }

        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);

            // Observe the kNetworkReachabilityChangedNotification. When that notification is posted, the method reachabilityChanged will be called.
            NSNotificationCenter.DefaultCenter.AddObserver(new NSString(Reachability.ReachabilityChangedNotification), OnReachabilityChanged);
        }

        public override void ViewDidDisappear(bool animated)
        {
            base.ViewDidDisappear(animated);
           
        }

        private void OnReachabilityChanged(NSNotification notification)
        {
            var reachability = notification.Object as Reachability;
            UpdateInterfaceWithReachability(reachability);
        }

        private void UpdateInterfaceWithReachability(Reachability reachability)
        {
            if (reachability == hostReachability)
            {
                var networkStatus = reachability.CurrentReachabilityStatus();
                var connectionRequired = reachability.ConnectionRequired();

                Console.WriteLine(networkStatus.ToString());

                if (networkStatus == NetworkStatus.NotReachable)
                {
                    var okAlertController = UIAlertController.Create("Connection Issue", "No Wi-Fi", UIAlertControllerStyle.Alert);
                    okAlertController.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null));
                    PresentViewController(okAlertController, true, null);
                }
                else
                {
                    var okAlertController = UIAlertController.Create("Connection Issue", "Wi-Fi Connected", UIAlertControllerStyle.Alert);
                    okAlertController.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, async (action) => await ConnectDongle()));
                    PresentViewController(okAlertController, true, null);
                }
            }
        }

        protected override void Dispose(bool disposing)