Button to quit app

1

I'm developing an example app for Iphone using Xcode with Swift 3.0. I need to put a button that when clicked closes the whole application. I could not identify any event or function that does this.

    
asked by anonymous 27.04.2017 / 00:44

1 answer

0

There is a method to "exit" the application:

exit(0)

UPDATE

Quoting the Jeff Wolski answer:

According to Apple's Human User Guidelines ...

  

Do not terminate the application by code

     

Never end an iOS application with code, as your users tend to   to interpret this as a crash. However, if any   prevent your application from working as it should, you should   inform the user about this situation and explain what it can   do about it. [...]

If, however, you want to terminate your application ...

In C , exit(0) will stop executing the application suddenly ("0" is the count status that says the shutdown has occurred successfully). This means that no delegate method or exception algorithm will be invoked. So if your goal is to make sure that some code is called before you quit the application, even if forced, there might be a better way to do that. On your AppDelegate , implement a custom method like: -(void)applicaitonIsgoingAway . Call this method inside where you want to end the application:

  • applicationWillTerminate
  • applicaitonDidEnterBackground
  • onUncaughtException
07.06.2017 / 14:49