3

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

Jawa
  • 2,336
  • 6
  • 34
  • 39
Wallace
  • 33
  • 1
  • 3
  • Where do you call exit() function? May be that code gets called when device wakes up from hibernation... – Vladimir Feb 19 '10 at 14:50
  • I have a method in the application delegate which handles the exiting of the application. In this method applicationWillTerminate is called before exit(0). When debugging I get to exit(0) and then it restarts. – Wallace Feb 19 '10 at 14:55
  • 2
    I fail to understand what you are trying to do. Why are you forcefully terminating the app? And to answer your question about gracefully terminating the app, no, there is no way to do that properly because it's not intended behaviour of any application on the iPhone. – Jasarien Feb 19 '10 at 16:50
  • This appears to be a duplicate of this question: http://stackoverflow.com/questions/355168/proper-way-to-exit-iphone-application – Brad Larson Feb 20 '10 at 01:47
  • Exiting the application was part of the business logic of the application, but after more research and apple's discouragement of exiting without the user hitting the home key. The business logic has been changed. – Wallace Mar 03 '10 at 21:17

5 Answers5

3

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
  • 17,253
  • 17
  • 63
  • 98
1

You can use this private command to quit your app with an animation (after you added the UIApplicationExistsOnSuspend key in your Info.plist) :

[[UIApplication sharedApplication] suspend];

But your app will be rejected if you want to put it in the App Store

Philippe97
  • 380
  • 4
  • 9
0

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)

Community
  • 1
  • 1
Yannick Loriot
  • 7,107
  • 2
  • 33
  • 56
0

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

-1
//@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 ....

Dan J
  • 25,433
  • 17
  • 100
  • 173
iXcoder
  • 1,564
  • 4
  • 20
  • 41