Is there any way to programmatically send my iPhone app to the background

Already answered quite well here:

Suspend the application

As that poster wrote:

Quitting your application or sending it to the background programmatically is a violation of the [iOS Human Interface Guidelines][1], which usually doesn't bode well for getting through the review process:

Don’t Quit Programmatically

Never quit an iOS application programmatically because people tend to interpret this as a crash. However, if external circumstances prevent your application from functioning as intended, you need to tell your users about the situation and explain what they can do about it. Depending on how severe the application malfunction is, you have two choices.

Display an attractive screen that describes the problem and suggests a correction. A screen provides feedback that reassures users that there’s nothing wrong with your application. It puts users in control, letting them decide whether they want to take corrective action and continue using your application or press the Home button and open a different application

If only some of your application's features are not working, display either a screen or an alert when people activate the feature. Display the alert only when people try to access the feature that isn’t functioning.


In Swift 3 Use below code, working charm

  DispatchQueue.main.asyncAfter(deadline: .now()) {
          UIApplication.shared.perform(#selector(NSXPCConnection.suspend))
      }

While I agree with the other answer that you "shouldn't" exit programatically. There is a way to exit programatically.

*disclaimer - You shouldn't do this.

exit(0);

There is no way to put the application into the background without pressing the home button. If there is, you might want to add the jailbreak flag to your question and ask them.

For more, check this duplicate question, Proper way to exit application.

Tags:

Ios