1

I am developing a web-based application where I need to launch the application only when my server is up for a particular host. If the network connection is not available I am planning to show an alertview to re-launch the application. I am using this:

    NSURL *scriptUrl = [NSURL URLWithString:@"http://lmsstaging.2xprime.com"];
    NSData *data = [NSData dataWithContentsOfURL:scriptUrl];

    if (data != nil) {
//Launch my application
}
else {
//show an alert
}

But the problem is that, when I click on the "OK" button in the alert view, I want my application to quit. Is this the right way to do this? Can someone suggest any other option to overcome this scenario?

Widor
  • 13,003
  • 7
  • 42
  • 64
Pradeep Reddy Kypa
  • 3,992
  • 7
  • 57
  • 75

1 Answers1

1

There is no "official" way to quit. Apple recommends your alert to say something like: "Network connectivity required for this application. Press the home button to quit."

Owen Hartnett
  • 5,925
  • 2
  • 19
  • 35
  • Harnett: Can u please let me know if this is the right way to check the network connection? – Pradeep Reddy Kypa May 23 '12 at 16:14
  • That will work OK, except that it's synchronous, so it will tie up your app until it times out. You should look at the Reachability example code for Apple's correct way of finding out whether you're connected or not. – Owen Hartnett May 23 '12 at 16:18
  • Harnett: Can u suggest any way on how to create an asynchronous check? I have checked the Reachability code but i found it too messy for this requirement. Frankly,i am not able to understand the flow of that code and to grab my actual requirement from that code. It would be very helpful if u can suggest anything on this. Thanks again for ur time. – Pradeep Reddy Kypa May 23 '12 at 16:30
  • http://www.youtube.com/watch?v=OSZB6T1IUp0 – Owen Hartnett May 23 '12 at 17:06