Which applications launch into background state? - iphone

I'm reading through the multitasking documentation, and it has a few references to apps which launch directly into the background state, never entering the foreground state. Is this really allowed for regular apps? Can anyone give me an example of an app like this?

VoIP apps are the biggest one to use this feature. Basically a VoIP app can register itself with the system to be notified when network traffic is intended for it at which point the app takes over handling the incoming traffic (i.e. receiving a call). Skype and Viber both use it.
From the iOS Developer Library (emphasis mine):
Including the voip value in the
UIBackgroundModes key lets the system
know that it should allow the
application to run in the background
as needed to manage its network
sockets. An application with this key
is also relaunched in the background
immediately after system boot to
ensure that the VoIP services are
always available.
The significant location changes backgrounding service also allows an app to be updated with the new location even if it's not running.
Other than those two cases, an app can't do anything from a terminated state until the user launches it.

When you use location manager with significantchange notification, App gets backgrounded automatically if the app is killed, when there is a location event

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.

Does Apple approve the usage of setKeepAliveTimeout:handler methode for updating GPS location to server?

I'm writing an application that needs once in a while to update the server about the user's location while the application is running in the background. I know I can do this by using the setKeepAliveTimeout:handler: method. I know that this method is specially for VoIP application but I was wondering if Apple will allow this usage for location update to server?
The documentation says that your handler only get 10 seconds to keep the network connection alive for voip calls when using setKeepAliveTimeout:handler: method. See this answer.
This call is for voip apps and you must have voip in your UIBackgroundModes key (info.plist). Using this would probably get rejected unless you are writing a voip app.
You don't need this setKeepAliveTimeout.
I recommend to read this Apple's officatin documentation:
https://developer.apple.com/library/ios/documentation/userexperience/conceptual/LocationAwarenessPG/CoreLocation/CoreLocation.html
One of the things, which iOS provide is a callback on a location change. Your application will be awoken for short period of time and you will receive this callback and should be able to send your location to the server.
BTW. You will need location backgrounding mode for this.
And progmr is right. You will need voip backgrounding mode to use setKeepAliveTimeout. And if your application isn't a real voip application, almost guaranteed that your app will be rejected.

Start a location-aware background service in iOS on boot

Applications can register for significant location changes.
(Recommended) The significant-change location service offers a
low-power way to receive location data and is highly recommended for
applications that do not need high-precision location data. With this
service, location updates are generated only when the user’s location
changes significantly; thus, it is ideal for social applications or
applications that provide the user with noncritical, location-relevant
information. If the application is suspended when an update occurs,
the system wakes it up in the background to handle the update. If the
application starts this service and is then terminated, the system
relaunches the application automatically when a new location becomes
available. This service is available in iOS 4 and later, only on
devices that contain a cellular radio.
From https://developer.apple.com/library/archive/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html
An app can be relaunched when the location changes. However, can it be started automatically when the phone is started? The documentation isn't quite clear.
The service will start when the user launches your application, and terminate if it is closed. The service will remain running if the application is running in the background.
Developers cannot integrate services into the OS, for security purposes.
No, you cannot have your application run automatically when the phone is started. In addition, if the user starts your application manually and puts it into the background, the system may eventually kill it when it needs the memory.
"Including the voip value in the UIBackgroundModes key lets the system know that it should allow the app to run in the background as needed to manage its network sockets. An app with this key is also relaunched in the background immediately after system boot to ensure that the VoIP services are always available."
check iOS docs here
Although if you do this for an illegitimate reason I am guessing your app will either not get approval or get booted quickly.