Update my app when it is in background
Asked Answered
F

5

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 ??

Freestyle answered 16/2, 2012 at 11:16 Comment(3)
Refer [Link][1] [1]: #4594848Mask
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 stateFreestyle
Does this answer your question? What is Silent Push Notification? When does the device receive it?Rodenhouse
P
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.

Poul answered 16/2, 2012 at 11:27 Comment(4)
@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 ??Freestyle
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.Poul
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.Freestyle
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.Poul
C
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.

Corruption answered 17/2, 2012 at 4:11 Comment(0)
S
-1

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.

Schadenfreude answered 16/2, 2012 at 11:46 Comment(4)
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)Freestyle
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.Schadenfreude
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.Freestyle
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.Schadenfreude
L
-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.

Laborsaving answered 29/1, 2013 at 10:59 Comment(0)
H
-1

iOS 13.0 introduced a BackgroundTasks framework that enables applications to request bits of execution time while in the background. The link references the Apple developer documentation for that framework.

Housebreaking answered 18/9, 2023 at 19:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.