views:

489

answers:

4

I have an iPhone application which will exit on it's own after a user completes a particular action. I currently use exit(0) to leave the application and I have had no troubles with it until recently. I understand that this isn't the "right" way to exit an application but it is something that I want to do. The issue I am having is when the device awakes from hibernation, with my application as the active one, exit(0) is called and the application would restart after exiting.

This strikes me as quite odd and am wondering if this is a bug or am I doing something wrong? Is there a better way to gracefully exit an application without having the user hit the home key?

Thanks

A: 

There is a link here where may be have your answered: link text

But it doesn't exist public API to terminate programmatically your iphone application. (see Technical Q&A QA1561 from the iPhone Dev Center)

Yannick L.
+2  A: 

Apple's way is to alert the user that the app is finished and they must click home to quit. You shouldn't do this in your code. If its obvious that your app is quiting to reviewers then it most likely won't get approved.

jamone
A: 
    //@step invoke the normal routine applicationWillTerminate

if ([[UIApplication sharedApplication].delegate respondsToSelector:@selector(applicationWillTerminate:)]) { [[UIApplication sharedApplication].delegate performSelector:@selector(applicationWillTerminate:) withObject:[UIApplication sharedApplication]]; } //@step force quite app kill(getpid(), SIGINT);

I think that is no private API was used ....

Robin
A: 

I see the same issue. I was able to stop this by calling exit(1) instead.