2

I want to update some data to my application. Consider the application is in the background state, it is neither Voip or Music or GPS. Is it possible to update/send data to the application which is in background?

NOTE: I dont want to notify the user so that the application becomes active.

Can anyone help me ??

Cyril
  • 1,216
  • 3
  • 19
  • 40
  • Refer [Link][1] [1]: http://stackoverflow.com/questions/4594348/iphone-connecting-to-server-in-background/ – Apurv Feb 16 '12 at 11:21
  • I have read the apple document,regarding running the finite and long running tasks.But here i wanna send datas from the server to the app, irrespective of the state – Cyril Feb 16 '12 at 11:42

4 Answers4

4

The answer is yes and no.

Apple does allow you app to complete a lengthy process in the background. But if you does not fall in the Voip, music or GPS category then you can't run in background.

If for example you want to send some data to a server, which could take some time, then you can mark that process to back executed until it is finished (or 10min. have passed).

You will find some about Executing a Finite-Length Task in the Background

There is not way to run timers or any thing like that in the backgroud, you can only finish a task you started before the app is backgrounded.

UPT
  • 1,490
  • 9
  • 25
rckoenes
  • 69,092
  • 8
  • 134
  • 166
  • @rckoenes.Thanks for your reply. I have went through the Multitasking and Background execution apple document. I want to do it in other way. I want send notifications/data from the server to the app(running in background). I know, by sending push notifications we can make that app active, where i dont want to make my app come to foreground. The app should remain in the background and update data. Is that possible ?? – Cyril Feb 16 '12 at 11:39
  • No that is not possible. Also sending a push notification will not bring the app to the foreground, only after a user open the push notification will you are come to the foreground. – rckoenes Feb 16 '12 at 12:13
  • Sorry , you misunderstood me. I know sending only push notification will not make the app to come foreground unless the user responds to the notification. I was trying to update data from server, when the app is in background. – Cyril Feb 16 '12 at 12:37
  • 1
    Sorry, I just want to be clear. But the answer is still that you will not be able to do what you want. One reason I could think of why you don't want this is battery life. – rckoenes Feb 16 '12 at 12:47
0

The alert which is displayed is an inbuilt functionality. You can't do anything for that. If a notification is fired from the server and application is in background then the alert will be displayed. I have done a lot of search in past for this stuff.

iamsult
  • 1,581
  • 1
  • 15
  • 21
  • Yes. I know that the user will be alerted at any cost, atleast sound. But I dont want to bring the app to the foreground and update my data. After alerting the user, I want to update data to the app (without making the app to come foreground) – Cyril Feb 16 '12 at 12:07
  • First of all you can't capture the event of the "View" button, so how you can handle the app coming to the foreground. One more thing you will be violating the HIG guidelines as well by doing so. – iamsult Feb 16 '12 at 12:12
  • I dont want to make the app move to foreground on its own or sending any push notification. Let the app be in background state, I want to update while it is background. – Cyril Feb 16 '12 at 12:43
  • 1
    No it is not possible. If you click on "close" button the event will not intimate the app. As i mentioned above we cannot handle the "view" button event. So the thing you are trying to achieve is not possible. So don't waste your time. – iamsult Feb 16 '12 at 12:46
0

I have done this in one of my work. this is what i did.

when application enter : - (void)applicationDidEnterBackground:(UIApplication *)application

I send data to server using ASIHTTPRequest with property : [request setShouldContinueWhenAppEntersBackground:YES];

But after finished, i didn't do anymore connection or data manipulation. So, only the connection is running at background and not your app. you can't do much after the connection finish.

As @rckoenes was mentioned, you may not execute task too long.

HelmiB
  • 12,303
  • 5
  • 41
  • 68
-1

If you would like to update server data while your app is running in the background mode, the application should be active at that time. It can only be active if it uses "music, or voip, or location tracking", otherwise the app will be paused in background mode.

One way to avoid this is to develop your application, and to set it to use, for example, «location tracking». This will allow it to meet the requirements for active background process and you will be able to update server data.

Unfortunately, I do not know whether the app can pass app store approval with this set-up. However, if you are interested in this solution, you can find an example here.

iOSdev
  • 1
  • 1