Running iPhone Apps In The Background

by: | May 15, 2009

How To Run iPhone Apps In The Background

We’re regularly asked by clients if it’s possible to create iPhone apps that continue running in the background when another app is launched, and then can resume when they are returned to the foreground. So we’ve put together an FAQ of the frequently asked questions about “running iPhone apps in the background” and the answers.

Updated post: With more recently versions of iOS much of this has changed. It’s now possible have iOS apps continue running in the background and you can use silent push messages or GPS based geo-fencing techniques to have your app automatically return to the foreground at appropriate times. Please contact us if you have any questions and our app development team can give you an honest assessment of what can and can’t be done technically.

Can applications run in the background while other apps are running?

Generally, the answer is “no.” There are two exceptions, however. The iPhone “Phone” application (where you make calls), and the iPod application can run at the same time as your application. If you make a phone call or play some music, then press the Home button and launch your app, the phone call continues and the music continues. This is documented by Apple in their iPhone OS Tech Overview, which states: “The iPhone SDK supports the creation of native foreground applications that appear on the device’s Home screen only. It does not support the creation of other types of code, such as drivers, background applications, frameworks, or dynamic libraries.”

But what about Mail? It checks mail in the background?

Mail is special, like all Apple apps. Apple’s own apps are allowed to run in the background, but they have not opened the Application Programming Interfaces (APIs) up so that other apps can do it. Mail checks for mail in the background, the Clock has an alarm that can wake the phone up, the Phone apps can receive calls, the App Store checks for updates, the Calendar alerts you of appointments, and the iPod can continue playing music.

If Apple can do it, can we use some secret way to run a background app?

Not really. You can use “private” APIs, but it is expressly forbidden in the iPhone SDK Agreement. It reads: “Applications may only use Published APIs in the manner prescribed by Apple and must not use or call any unpublished or private APIs.” Although you can do it during your app development process, your app will almost certainly be rejected by the iTunes app store review process when you submit it for public distribution.

But a friend has an app that seems to run in the background. How is that done?

One option is to write an app that uses private APIs for private distribution. This means that you are distributing the app outside of Apple’s control, directly, to your users. You use a technique called “ad-hoc” distribution or “enterprise” distribution. “Ad-hoc” is limited to 100 users (although 75 is a more typical limit when you incorporate developers, testers, etc.), and “enterprise” is typically used by corporations for their enterprise mobility solutions – those internal apps used only by their employees (B2E), such as for field sales enablement.

Can my app “wake up” at periodic intervals or at specific times?

No. Because there is no background app processing, there’s no way to wake up your application either at regular intervals or at specific times.

Isn’t there any way that my app can do something at regular intervals?

Yes, there are several options. 1) you can set your iPhone to not sleep, or to sleep after a longer period of time. Then your app can continue doing its stuff without worrying about the iPhone turning off. 2) you can have your app do something immediately upon launching, such as recording an event, determining your location via GPS, or something else. While the user has to start your app, you can make it quite seamless to continue where you left off.

What about using “push notifications” to trigger my app to do something?

From Apple’s web site: “The Apple Push Notification service provides a way to alert your users of new information, even when your application isn’t running. Send text notifications, trigger audible alerts, or add a numbered badge to your application icon.” What this means is that you can alert a user of something, at any specific time… but it can only beep (or whatever you have the system’s alert sound to play), vibrate, show a text message, or add a numbered badge on your app’s icon. That’s it. It cannot launch your app. You could use the Apple Push Notification service to alert your user to run your app, which would then pickup right where it left off. Push notifications are a very powerful and often under-utilized way of engaging with users to get them to return to your app.