0

I am developing an app that requires an internet connection, so I want to check the availability before launch. If internet connection it is not available, show an alert to the user and go back to Home instead of trying to launch the app.

So I used the Reachability class, that was recommended here (http://stackoverflow.com/questions/1961341/check-for-internet-access-with-monotouch) to check the internet connection. So far so good. But if I place this check in my Main.cs, it performs the check, but will not display the alert.

if(!Reachability.IsHostReachable("http://google.com")) {
                Debug.WriteLine("OFFLINE");
                UIAlertView alert = new UIAlertView("Offline","Voor deze app is een internetverbinding vereist.",null,"OK",null);
                alert.Show();
            }
            else{           
            MPFramework.Application app = new MPFramework.Application();
            UIApplication.Main (args, null, "AppDelegate");         
            }

If I place this check in AppDelegate.cs it performs the check, displays the alert, but keeps a black screen instead of returning to Home. So where do I place my code in order to check before launching the app, and displaying an alert?

Ronald
  • 417
  • 5
  • 11

1 Answers1

3

You're looking at this a bit wrong:

  • Apple doesn't approve of apps that kill/close themselves (see this: https://stackoverflow.com/a/356342/183422). If the user wants to close your app, he should do it himself.

  • You need the main loop running to show any UI - and that main loop is started when you call UIApplication.Main (which is why you have to do the check in AppDelegate.cs and show the corresponding alert there instead of in your Main method).

So, putting these things together, I think you should show a blank/splash screen, check for reachability and if there is none then show the alert (and if the user dismisses the alert, maybe check again).

Community
  • 1
  • 1
Rolf Bjarne Kvinge
  • 19,253
  • 2
  • 42
  • 86
  • Thanks for your answer, I was aware of Apple's policy, that's why I wanted to check before the app actually launches. Which doesn't seem to be the way either. But if you're building an app which contents are in the cloud, then launching a completely empty app didn't seem to make sense... – Ronald Jun 07 '12 at 07:24