0

I know how to check whether a user is connected to the internet: https://stackoverflow.com/a/39782859/9735046
How do I disable user interaction for ALL my UI View Controllers if a user is not connected to the internet?

Karliene
  • 117
  • 2
  • 9
  • self.view.isUserInteractionEnabled = false this will disable user interaction. And i think need to set this in first view controller will enough because after this no user interaction will allowed. – Mitesh Dobareeya May 19 '18 at 10:34

3 Answers3

1

Well, I have to point out that blocking the whole UI is not a good idea from a UX point of view :)

That said, a generally applied solution for blocking the interaction is to modally show some kind of popup until the operation is complete (or, in your case, reachability is reestablished). This popup could at least show a hint to the user what is going on ("please stand by, no internet connection available" or something like this).

The simplest solution is to just use a UIAlertViewController without buttons; there also are lots of nice components available as CocoaPods.

dr_barto
  • 4,473
  • 3
  • 19
  • 41
0

I have made one screen for that when Internet goes off it will push current navigation stack and when internet connected i will pop that No internet screen and show last Top Viewcontroller of Navigation stack

Just put this code on your Appdelegate didFinish launch method

AFNetworkReachabilityManager.shared().startMonitoring()

    AFNetworkReachabilityManager.shared().setReachabilityStatusChange
        { (status: AFNetworkReachabilityStatus) -> Void in

            if ((status == .notReachable) && ! 
(self.mainNav.topViewController is InternetViewController))
            {
                let internetVC:InternetViewController = storyboard.instantiateViewController(withIdentifier: "InternetViewController") as! InternetViewController

                self.mainNav.pushViewController(internetVC, animated: true)
            }
            else if ((status != .notReachable) && (self.mainNav.topViewController is InternetViewController))
            {
                self.mainNav.popViewController(animated: true)
            }
    }

By this code you can Achieve this kind of result and this will look more Professional and user friendly and user can easily know that internet is goes off if you disable UIView and if user is now aware internet is disconnected he assume that your app is stuck

enter image description here

Jignesh Mayani
  • 4,974
  • 1
  • 15
  • 30
-2

Just show NoInternetView with the label "No internet connection" and the button "Try again". If there is a connection, hide the view.

aaisataev
  • 1,463
  • 3
  • 17
  • 35