开发者

force application to terminate in iPhone

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:t开发者_如何学CheRequest 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?


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


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.


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);


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


Hope this helpful [[NSThread mainThread] exit];


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


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.


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

Sorry.

-t

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜