0

We do not want to use exit(0) to make the app close, we do however want to allow the app to go to background programmatically and process away, per users allowing this action. Is there a way to send the app to the background programmatically without exit? Simulating the click of the home button?

Thank in advance!

mejim707
  • 431
  • 3
  • 16

3 Answers3

2

Is there a way to send the app to the background programmatically without exit?

No. The user is supposed to be in control of the app -- the app shouldn't move to the background (or exit) of its own accord.

Caleb
  • 124,013
  • 19
  • 183
  • 272
  • But, I've read in many places that the app could get rejected using exit(0). We don't want this. We do however want to give users the ability to set an option that allows the app to simply minimize itself while it processes and they do other things. We have background process working amazing but, we have options to do this action automatic. We don't want to break this with exit(0) – mejim707 Apr 02 '12 at 02:36
  • 1
    What you want to do and what you're *able* to do are two different things, I'm afraid. The best solution would be to allow your app to remain useful to the user while it does whatever processing you're talking about. If that's not possible, let the user know what the app is doing and let them hit the home button if they want to. Don't call exit() -- let the user keep control. – Caleb Apr 02 '12 at 03:00
1

Not possible. Home button clicks run into the private GSEvents framework. It's exit() or none unfortunately.

CodaFi
  • 43,043
  • 8
  • 107
  • 153
  • But, I've read in many places that the app could get rejected using exit(0). We don't want this. We do however want to give users the ability to set an option that allows the app to simply minimize itself while it processes and they do other things. We have background process working amazing but, we have options to do this action automatic. We don't want to break this with exit(0) – mejim707 Apr 02 '12 at 02:36
  • Ironically a lot of Zinga apps use the exit function – CodaFi Apr 02 '12 at 02:37
  • But this causes background processing to not work because the app does in fact terminate, unclean, but it does. We need the background tasks to complete. – mejim707 Apr 02 '12 at 02:42
  • Why not just present a loading alert and ask that they close the app if it's taking too long? – CodaFi Apr 02 '12 at 02:43
  • I guess we could. I've been bouncing an idea like this with a colleague. but, it seems a little hokey honestly. The user should be able to set an option to auto close and run for them. Not preset an option saying "hey, you wanted the app to close but to do this you need to push the home button". – mejim707 Apr 02 '12 at 02:49
  • Thanks for the comment though CodaFi! Crazy stuff this devel work – mejim707 Apr 02 '12 at 02:53
  • 1
    It won't be that hokey. Just remind the user of how long it'll take, gently recommend that they close the app, then finish the deal by reminding them that the work will be finished when they come back. – CodaFi Apr 02 '12 at 03:23
0

The below code can be used to send iOS app to background programatically without exit

DispatchQueue.main.async {
        UIApplication.shared.performSelector(inBackground:NSSelectorFromString("suspend"), with: nil)
    }