tags:

views:

38

answers:

1

Hi, In order to run the app continuously in the background on the 3GS and iPhone4 on OS4.1 is it simply enough to call BeginBackgroundTask in the DidEnterBackground callback and then NOT call EndBackgroundTask ie to leave it running. I understand this will run the battery down but that is ok as my users will be running on power.

If this is not the way to do it , can someone say how to keep the app running (not suspended)

Thanks

+5  A: 

You cannot keep the app running on the background.

You can declare some tasks that the system will run in background.

According to the Apple documentation:

Support for some types of background execution must be declared in advance by the application that uses them. An application does this by including the UIBackgroundModes key in its Info.plist file. This key identifies which background tasks your application supports. Its value is an array that contains one or more strings with the following values:

audio - The application plays audible content to the user while in the background. location - The application keeps users informed of their location, even while running in the background. voip - The application provides the ability for the user to make phone calls using an Internet connection. Each of the preceding values lets the system know that your application should be woken up at appropriate times to respond to relevant events. For example, an application 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 application at appropriate intervals. If the application did not include this key, any audio being played by the application would stop when the application moved to the background.

In addition to the preceding keys, iOS provides two other ways to do work in the background:

Applications can ask the system for extra time to complete a given task. Applications can schedule local notifications to be delivered at a predetermined time. For more information about how to initiate background tasks from your code, see “Initiating Background Tasks.”

Junior B.
Right. You can use the beginBackgroundTaskWithExpirationHandler: method to ask for extra time in the background, but note that it's not unlimited -- query the `backgroundTimeRemaining` property on UIApplication to see how much time you have left. (With the current OS, limit seems to be 10 minutes).
David Gelhar
Well , if an app is playing audio it is running all the time. So am i right in thinking some apps can be running all the time IF they are playing audio even if it is fake like hotpaw suggested
tech74