0

I am now developing an application on iPhone . There is a function in the app that I use it to update some information periodically from server side.

Is there any method to keep the update process running (somewhere in memory or so) when I close the app? and then can restore the information when I restart the app?

Sara Houssein
  • 47
  • 2
  • 7

3 Answers3

2

If what you mean is:

Is it possible to keep running code if the user kill my app ?

Then the answer is no.

But if you mean:

Is it possible to keep running code while my app is in background ?

Then you can use UIBackgroundTaskIdentifier (documentation here).

This post explains it pretty well

Community
  • 1
  • 1
Tomusm
  • 2,208
  • 19
  • 20
0

there is a limit on what you can do when your app is in background, from this link: Background Execution and Multitasking

Declaring Your App’s Supported Background Tasks

Support for some types of background execution must be declared in advance by the app that uses them. An app declares support for a service using its Info.plist file. Add the UIBackgroundModes key to your Info.plist file and set its value to an array containing one or more of the following strings:

audio—The app plays audible content to the user while in the background. (This content includes streaming audio or video content using AirPlay.)

location—The app keeps users informed of their location, even while it is running in the background.

voip—The app provides the ability for the user to make phone calls using an Internet connection.

newsstand-content—The app is a Newsstand app that downloads and processes magazine or newspaper content in the background.

external-accessory—The app works with a hardware accessory that needs to deliver updates on a regular schedule through the External Accessory framework.

bluetooth-central—The app works with a Bluetooth accessory that needs to deliver updates on a regular schedule through the CoreBluetooth framework.

Each of the preceding values lets the system know that your app should be woken up at appropriate times to respond to relevant events. For example, an app that begins playing music and then moves to the background still needs execution time to fill the audio output buffers. Including the audio key tells the system frameworks that they should continue playing and make the necessary callbacks to the app at appropriate intervals. If the app does not include this key, any audio being played by the app stops when the app moves to the background.

Community
  • 1
  • 1
Andrei G.
  • 1,710
  • 1
  • 14
  • 23
  • 10x for u reply but what I meant that if the user closes the application, it becomes as it's not lunched yet so it's not running on background. It quits totally. is there any way to keep the update process running while the application is not lunched? – Sara Houssein Jul 21 '12 at 09:36
  • when app goes to suspended state, it can no longer execute any code, except above background modes - audio, location, voip etc. – Andrei G. Jul 21 '12 at 10:16
0

Try ASIHTTPRequest, they have a method for that.

Parvin Gasimzade
  • 25,180
  • 8
  • 56
  • 83
  • you can finish a currently running network task in background, but you can't start a new one from background. ASIHTTPRequest is no longer supported by the author, and he recommends using some other solutions for a good reason. – Andrei G. Jul 22 '12 at 00:25