1

Is there a way to close the iPhone app from within the app? A client asked me if there was a way to close the app by pushing a button in the app, without manually doing it by double tapping the home button and then press-hold the app icon and then hit the - sign.

Apparently, the client wants to build an app which uses bluetooth and ANT+ devices which are battery hogs and wants the ability to quickly close the app.

Any thoughts?

wackytacky99
  • 614
  • 1
  • 14
  • 33
  • 1
    You could `exit()` in response to a button press event, however somewhere in the guidelines it says that this is not allowed for an App Store app. I have seen apps which do exactly that, though. – Joost Nov 07 '12 at 21:15
  • See this question: http://stackoverflow.com/q/355168/251760 – Jonathan Nov 07 '12 at 21:15
  • 2
    how'bout setting the `UIApplicationExitsOnSuspend` Info.plist key to true? –  Nov 07 '12 at 21:15
  • UIApplicationExitsOnSuspend I'm going to give that a shot. Thanks – wackytacky99 Nov 07 '12 at 21:17
  • Note: UIApplicationExitsOnSuspend will disable the multitasking feature of your app. – iDev Nov 07 '12 at 21:18

3 Answers3

3

I'm thinking you should just make the button dispose of the Bluetooth and other 'battery hogs'. You might even make the app smart enough to turn it off based on certain events like when the user leaves the app or when a certain function is completed.

MetaGuru
  • 42,847
  • 67
  • 188
  • 294
1

Aside from quitting from a button within the application being against the Apple Human Interface Guidelines, it isn't even recommended behaviour.

But if you still want to close your app. Use 'exit();'.

Community
  • 1
  • 1
hd1
  • 33,938
  • 5
  • 80
  • 91
  • 1
    And this isn't even an answer. –  Nov 07 '12 at 21:16
  • 1
    No, it's not, it's meant as a stern warning that such apps should not pass the iTMS approval process and is, therefore, something to keep in mind. – hd1 Nov 07 '12 at 21:18
0

This behavior is against Apple's Human Interface Guidelines. If you still want to do so, use the C function exit();. But for the user this will look like the application crashed, so I wouldn't do so, even not on an non-AppStore app!

miho
  • 11,765
  • 7
  • 42
  • 85