Button to quit app

Asked

Viewed 272 times

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 entire application. I couldn’t identify any event or function that does this.

1 answer

0

There is a method to "exit" the application:

exit(0)

UPDATE

Quoting the reply of Jeff Wolski (translated into English):

According to Apple’s Human User Guidelines...

Do not close the application by code

Never terminate an iOS app by code, as your users tend to to interpret this as a crash. However, if any circumstances external prevents your application from working as it should, you should inform the user about this situation and explain what he can do so. [...]

If, even so, you want to terminate your application...

In C, exit(0) will interrupt the execution of the application suddenly ("0" is the earl status which says the closure has successfully occurred). It means that no method of delegate or exception algorithm will be called. So if your goal is to make sure some code is called before you close the application, even if it’s forced, maybe there’s a better way to do that. In his AppDelegate, implement a customized method such as: -(void)applicaitonIsgoingAway. Call this method within where you want to terminate the application:

  • applicationWillTerminate
  • applicaitonDidEnterBackground
  • onUncaughtException
  • 1

    Do you have any official documentation on this method? If yes, it would be nice to put the link of the same in the answer to serve reference and study material.

  • I used an answer in English to support the answer here.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.