views:

1316

answers:

8

I am developing an iPhone application which is completely based on web data.

If it is not connected to the internet, the application is of no use.

So, I want to terminate the application when connection is not found.

NSURL *tmpURl=[NSURL URLWithString:[NSString stringWithFormat:@"%@search.php",[iGolfAppDelegate getServerPath]]];
    NSMutableURLRequest *theRequest=[NSMutableURLRequest requestWithURL:tmpURl];
    con=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
    if(con){
        myWebData=[[NSMutableData data] retain];    
    } else { 
        //Yes I will provide two buttons on alertview "retry" & "close", & when user
        //taps on "close" => application should terminate.
        // i will send alertview & when user taps on button close then
        // what to write for terminating application?
        // Ok Ok. Don't terminate. User will terminate.
        // user is owner of iPhone 
        // let him choose what to do
        // wait till wifi connects
    }

The question is how to terminate the application?

( is exit(0) only the option for terminating application or is there any other option available? )

// ok I accept that I shouldn't terminate. but I can not close this question now.

+9  A: 

You might consider informing the user that they cannot use your application without an active network connection. Just terminating the application outright seems like a very unfriendly way of doing this; the user will simply see the app "disappear".

Every well-behaved app I've seen will at least give a notification before terminating.

Steven Schlansker
Very much this. Tell the user that the app doesn't work without a connection, and let them kill it themselves.
Stephen Canon
Also, it's not impossible for the network to simply drop out for a few seconds. It would be super frustrating to use such an app in an area with a spotty connection.
Kendall Helmstetter Gelner
+2  A: 

If you terminate it will look like your app has crashed!

Best to put up a message saying that there is no internet connection and give them an option to retry (in case they can get an internet connection), or choose to quite it themselves

Phil Nash
sugar
In this case, the boss is wrong. Period. Show them the text that **Nikolai Ruhe** posted in his answer.
Stephen Canon
@sagar If your "Boss" insists, point him/her to Apple’s documentation. Apple strongly discourages terminating an app programatically. I provided a link in my answer.
Nikolai Ruhe
@sagar: Your boss's idea will likely get his app rejected from the App Store. Blindly saying "the boss is right" when you know what you're doing will not achieve his likely goal (having a marketable app) isn't respectful, it's passive-aggressive.
Chuck
@Chuck, I think there may be cultural issues clouding things here. Overall I agree that you have to draw the line somewhere.
Phil Nash
+4  A: 

I would advise you to reconsider for 3 reasons

  1. It may appear that your app crashed.
  2. The user may get an internet connection while your app is up. In this case a 'Retry' would be best.
  3. I think Apple may actually not accept the app if it does that. It is for sure not what they would do if an Apple application needed an internet connection, and they do test to see what an app will do without a connection.

If (for whatever reason)you do want to do it you can use.

exit(0);
Joe Cannatti
sugar
In that case, you should have one button: "retry". Every application on the iPhone already has a "close" button -- the hardware home button -- and there's no need for you to implement another.
Stephen Canon
+13  A: 

Apple is is absolutely clear about this topic:

There is no API provided for gracefully terminating an iPhone application. Under the iPhone OS, the user presses the Home button to close applications. Should your application have conditions in which it cannot provide its intended function, the recommended approach is to display an alert for the user that indicates the nature of the problem and possible actions the user could take - turning on WiFi, enabling Location Services, etc. Allow the user to terminate the application at their own discretion.

See Technical Q&A QA1561

Nikolai Ruhe
+2  A: 

You shouldn't do this. Take a look at "Stopping" in the Human Interface Guidelines as you could possibly fail for submitting an App that does this, or at the very least provide for a strange user experience.

The link also shows the correct way to handle this, as in the iTunes Music Store app.

bpapa
+4  A: 

You could always just divide by zero. As a bonus, the implementation would reflect what a good idea this is.

Chuck
No. here application will terminate by an exception - "divide by zero".
sugar
So now you're upset that the application will terminate? For the love of pants, man, make up your mind!
Chuck
Looking at your reputation, I take this answer as a joke: +1
Nikolai Ruhe
It's a joke + it actually answers the question "is there any other option available?" as well as it can be answered given that this is something you shouldn't do. The opportunity to do both at once so seldom arises I had to take it.
Chuck
+1 Excellent suggestion.
Stephen Canon
+1  A: 

Your App will be rejected if you terminate when you cannot reach the Internet.

Sorry.

-t

Tim
A: 

Hope this helpful [[NSThread mainThread] exit];

Rubycell