How to specify that app must perform important tasks in the background? - iphone

I'm making an app that needs to run in the background. It plays online radio and at the same time must perform calculations.
I know there is a background expiration handler but it is very limited in time to my knowledge. Is there a way an app can perform calculations in the background for a very long time?
Someone mentioned something about specifying your app needs navigation and then it can keep doing important things. How?

From the Apple documentation:
Implementing Long-Running Background Tasks
For tasks that require more execution time to implement, you must
request specific permissions to run them in the background without
their being suspended. In iOS, only specific app types are allowed to
run in the background:
Apps that play audible content to the user while in the background,
such as a music player app Apps that keep users informed of their
location at all times, such as a navigation app Apps that support
Voice over Internet Protocol (VoIP) Newsstand apps that need to
download and process new content Apps that receive regular updates
from external accessories Apps that implement these services must
declare the services they support and use system frameworks to
implement the relevant aspects of those services. Declaring the
services lets the system know which services you use, but in some
cases it is the system frameworks that actually prevent your
application from being suspended.
Your app seems to be ok for the
Apps that play audible content to the user while in the
background,such as a music player app
While your app is playing music you can do the calculation you are mentioning. For more info check the Apple documentation here

Related

when my iphone receiving calls, and my app is in background, i want call some codes (alert coreblue4.0 device)

I have used ctcallcenter, and use beginBackgroundTaskWithExpirationHandler, so I have only 10 minutes to call my codes. How can I make it longer,the app proxBLE have achieved it?
From the Apple documentation, you can extend the execution time only in the below cases. In order to do that, you need to add the UIBackgroundModes key to info.plist file. See the detailed explanation below.
Implementing Long-Running Background Tasks
For tasks that require more execution time to implement, you must request specific permissions to run them in the background without their being suspended. In iOS, only specific app types are allowed to run in the background:
Apps that play audible content to the user while in the background,
such as a music player app
Apps that keep users informed of their
location at all times, such as a navigation app
Apps that support
Voice over Internet Protocol (VoIP)
Newsstand apps that need to
download and process new content
Apps that receive regular updates
from external accessories
Apps that implement these services must declare the services they support and use system frameworks to implement the relevant aspects of those services. Declaring the services lets the system know which services you use, but in some cases it is the system frameworks that actually prevent your application from being suspended.
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 Core Bluetooth framework.
bluetooth-peripheral—The app supports Bluetooth communication in peripheral mode through the Core Bluetooth 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.

iphone: backgrounded app sync webservice

I know this question may be a little bit common and over asked but I cannot find any precise information... so :
Is it possible to have some kind of thread running when the app is in background so I can perform basic sync with my webservice ?
App is in background : I mean the user clicked the Home button, or switched to another app
basic sync : photo upload and download with AFNetworking. I know it has method to continue an HTTPRequest while app is in background, but this is not my point.
My goal would be to make some kind of sync manager, reading a list of photos to update created while the user was on the app, and perform those changes.
I know that the manager could be killed by the OS, but since my server uses atomic transfers it is not a problem. I just need a way to relaunch it... Push ?
I think apps like Google Latitude or Mail and those kind of apps uses what I am looking for but I cannot find any relevant details on it. And using iOS5 is not a problem but waiting for iOS6 would not be a solution.
Thank you for your replies !
PS : well I almost forgot. the app is designed for an enterprise program, so maybe rules are different ? I don't think there is any check for in-house deployment so it might lead to new possibilities...
Apple's Mail client has a background daemon which keeps it running but you can't have that with your own applications. Once an app enters a background state, it must halt it's operations. You can request for a little more time when backgrounded to finish off any transfers or writes to disk (see the Executing a Finite-Length Task in the Background section on Apple's Multitasking Guide)
Google Latitude has events generated based on location. This is a special type of backgrounding introduced by Apple for certain types of applications (see Implementing Long-Running Background Tasks section on Apple's Multitasking Guide) but this can't be used for HTTP syncing. It can only be used for audio, location, voip, newstand content, bluetooth and external hardware attachments.
Push doesn't seem like a solution because it only generates an alert. It doesn't trigger any action until the user triggers the opening of the notification.
You'll want to read Tech Note 2277 Networking and Multitasking.
Basically you have a couple of options:
If you can convince Apple that your app is a VoIP app then you can register a VoIP socket and the OS will resume your background app whenever there is activity on that socket.
Your main option though is to register a background task for any outstanding activity that you have to do when your app is put in the background. You typically get 10 minutes to finish up that work.
Mail is a special app with privileges you don't get.
Apps like Latitude typically register themselves for location updates, specifically to be woken up when there are major geo-position changes. Apps that record GPS tracks do similar things.
Found it !
Using Suhail Patel 's link on Apple's Multitasking Guide I added the voip tag to UIBackgroundModes in Info.plist and use setKeepAliveTimeout:handler: method of UIApplication to relaunch it if needed once the app is going to sleep.
I hope this will help a lot of you !
Of course this app won't be allowed to be on the App Store but for in house development this is in my opinion the best way to do so.
Thanks everyone for showing me the right direction !

iOS background application network access

I have an application that requires location tracking and I think it fits squarely within one of the allowable background models. However, I need to post to a network service when there are significant changes of location. I've seen write-ups that state network access is prohibited in background processing, but I didn't read that in Apple's docs.
Does anyone know if it's kosher (wrt Apple policies) to make occasional and very quick network updates in a background process?
Good point, according to the Apple documentation only the following usages are allowed in background and each service should be registered:
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.
Other than this services, you can create a Finite-Length Task in the Background that actually give you the possibility to end a network process.
This can be important if your app is performing some important task,
such as writing user data to disk or downloading an important file
from a network server.
Regarding your question, it's not really clear if you can or not can do a quick network connection if you've a location service running in background. I would say YES for a short connection, but not totally sure. Since iOS 4.0 this usage was denied and clear in documentation, now that part has been removed.
Yes if you use background for just quick connection. Apple won't allow you to run in the background as you want.
NO If your app does not fall in the Voip, music or GPS category; then you can't run in background.
more here: Update my app when it is in background
You could use ASIHTTPRequest.
ASIHTTPRequest has a property setShouldContinueWhenAppEntersBackground:. default is NO, you may turn on YES so you have background network process.
Apple documentation seems a bit unclear on the strict policy. There are definitely applications in the app store that make sporadic network calls while running in the background as a location-based application. An example is the Geoloqi application.

app runs in background on ios4

I hope to run an app in background on ios4
I know
Apple allows only certain types of apps to run in the background, like navigation and audio and VOIP apps. But even those are limited to only the necessary tasks.
Is it possible I register the app as one kind of VoIP, Audio or GPS apps to keep it run in background?
Welcome any comment
You can't "run" an app in the background; you can only run a task in the background. The tasks are
Continue Playing Audio
Maintain VoIP Connection
Update Location (GPS)
Some Finite Task (such as uploading a file)
I haven't developed for iOS so there might be something I'm missing. Read more at Executing Code in the Background. As of iOS 4, developers don't have the ability to implement true multitasking. Correct me if I'm wrong in any of this.
Not in general, no. You could register a VoIP or GPS session and abuse its callbacks for certain tasks, but I doubt the App Store review process would take kindly to it.
What do you need to do in the background that isn't covered by task completion or the audio/VoIP/GPS background modes? it might be possible to use another paradigm and still get the cake.

iphone is it possible to register my application so the os notifies it every X seconds?

Hello I would like to know if there is an equivalent to the android's alarmManager so I can register my app to be waken every X seconds?
No. At least not directly Here's the list of all kinds of multitasking that Apple supports from its's What's new page:
Multitasking
iOS 4 delivers seven new multitasking
services that allow your apps to
perform tasks in the background while
preserving battery life and
performance. These multitasking
services include:
Background audio - Allows your app to play audio continuously. So
customers can listen to your app while
they surf the web, play games, and
more.
Voice over IP - Your VoIP apps can now be even better. Users can now
receive VoIP calls and have
conversations while using another app.
Your users can even receive calls when
their phones are locked in their
pocket.
Background location - Navigation apps can now continue to guide users
who are listening to their iPods, or
using other apps. iOS 4 also provides
a new and battery-efficient way to
monitor location when users move
between cell towers. This is a great
way for your social networking apps to
keep track of users and their friends'
locations.
Push notifications - Receive alerts from your remote servers even when
your app isn't running.
Local notifications - Your app can now alert users of scheduled events
and alarms in the background, no
servers required.
Task finishing - If your app is in mid-task when your customer leaves it,
the app can now keep running to finish
the task.
Fast app switching - All developers should take advantage of fast app
switching, which allows users to leave
your app and come right back to where
they were when they left - no more
having to reload the app.
Adding to Georg's answer, you probably want this:
Local notifications - Your app can now alert users of scheduled events and alarms in the background, no servers required.
Unfortunately it also requires the user to okay relaunching the app to run your code.