2

I have an app which can currently communicate with an server. Imagine the following case:

  1. User hits some buttons which triggers an server request.
  2. The request is send to the server and is processed.
  3. The user hits the home button (and maybe removes the app from the memory by hitting the home button two times).
  4. The script is done processing and returns it result.

Question: Will the device from the user gets this response (I am pretty sure it will not when removing from memory, but what when just closing the app)?

Hima
  • 1,249
  • 1
  • 14
  • 18

2 Answers2

2

There are 5 active states in iOS:

  • Not running: The app has not been launched or was running but was terminated by the system.

  • Inactive: The app is running in the foreground, but not receiving events. An iOS app can be placed into an inactive state, for example, when a call or SMS message is received.

  • Active: The app is running in the foreground, and receiving events.

  • Background: The app is running in the background, and executing code.

  • Suspended: The app is in the background, but no code is being executed.

On your third scenario where the user hits the home button, the app will be sent into the Background state, #4, and can still receive data and allow your script to run. If the user kills the app, (state #1) your script will not complete running.

So, to answer your question, yes your app will continue executing code if the user places it in the Background state, but not if they close the app because that will put your app in the Not Running state.

Henry F
  • 4,960
  • 11
  • 55
  • 98
  • 1
    Sorry little late, had some work to do, but better late then never right ;) –  Apr 25 '15 at 14:16
0
  1. Application is suspended (on the background, not running) - In this case the execution of you requests get paused. When your app gets to the foreground, usually the requests end with a timeout.
  2. Application is terminated - in this case the context of your application is lost and after restarting there are no running requests.

That's the 2 cases you should be concerned about. For me it a good solution to cancel all running requests when the application is entering background because it is easier to restart everything when the app gets to foreground again.

Also, you can setup background mode and that enables the app to perform some code when on the background but that's a more advanced topic.

Sulthan
  • 128,090
  • 22
  • 218
  • 270