I have an app which can currently communicate with an server. Imagine the following case:
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)?
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.
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.