How to programmatically exit the iPhone application?

I have an iPhone app that will exit after a user performs a specific action. I am currently using exit (0) to leave the application, and until recently, I had no problems. I understand that this is not the “right” way to exit the application, but this is what I want to do. The problem I am facing is when the device goes from sleep mode, while my application is active, exit (0) is called and the application restarts after exiting.

This seems rather strange to me, and I wonder if this is a mistake, or am I something wrong? Is there a better way to gracefully exit the application without clicking on the home key?

thank

+3
source share
5 answers

Apple's way is to alert the user that the application is finished, and they must press the home button to exit. You should not do this in your code. If it’s obvious that your application is being sent to reviewers, it will most likely not receive approval.

+3
source

You can use this private command to exit the application with animation (after you added the UIApplicationExistsOnSuspend key to your Info.plist):

[[UIApplication sharedApplication] suspend];

But your application will be rejected if you want to put it on the App Store

+1
source

, :

API, iphone. (. Q & A QA1561 iPhone Dev)

0

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

0
source
//@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 the private API was not used ...

-1
source

Source: https://habr.com/ru/post/1733535/


All Articles