Apr 01

Allowing 3rd party iPhone applications to run in the background is an often requested feature in the official SDK. Apple has responded that they can’t do that primarily due the increased, and unpredictable, battery drain. However Apple is also notorious for claiming that they are not working on something and they have absolutely no interest in working on it, until they surprise everybody with a working solution. With that in mind I decided to poke around a bit in the new 3.0 SDK.

There are 1,000 new API:s in 3.0, so there’s a fair amount of ground to cover, but a new framework called AsyncPRocessIngLibrary caught my attention. I have not been able to find any documentation for this framework, but it’s not in the PrivateFrameworks directory, so it’s presumably fair game.

Here’s an example of what you can do with this library that was discovered today:

UInt32 numProcessors = MPProcessorsScheduled();
/* Schedule task across available processors.
   Major hint of new hardware... */
for (n = 0; n < numProcessors; n++ ) {
   MPCreateTask( MyTask, kMPStackSize, NULL, NULL, taskOptions, taskID );

This is all pretty standard multi processing code. What’s new and interesting here is the taskOptions:

enum {
   MPTaskOptionNone                   = 0,
   MPTaskOptionTerminateOnAppExit     = 1 << 0,
   MPTaskOptionTerminateOnThreadDeath = 1 << 1,
   MPTaskOptionTerminateOnSemaphore   = 1 << 2,
   MPTaskOptionKeepRunning            = 1 << 3,
   MPTaskOptionLurad                  = 1 << 4,
   MPTaskOptionGetauscht              = 1 << 5
typedef UInt32 MPTaskOption;

Most of these flags are self-explanatory, but unless you set the 4/1 bit, they don’t behave as expected.


UInt32 taskOptions = (MPTaskOptionKeepRunning | MPTaskOptionLurad);

It’s important that before attempting to launch your background process, you first need to ensure that the device you’re running on is capable of this:

if ([[UIDevice currentDevice] isProcessFoolEnabled]) {
// start your process here

written by Nick \\ tags:

8 Responses to “How To Enable Background Processing Using iPhone SDK 3.0”

  1. Ken Pespisa Says:

    🙂 Well done. I especially like the “4/1” bit reference.

  2. jer Says:

    boy i hate this day…

  3. terry murphy Says:

    see and this opens up alot of what can be done. the use of more api will finally bring in relevant data to users beyond rss and maps. thanks for the write up


  4. iphone architect Says:

    i think i’ll use it for my clock app because for the moment i think it is not possible to set up a fire alarm without the clock running

  5. Daniel Byon Says:

    where do i find this framework? i’m looking at the frameworks directory of the 3.0 sdk and i can’t find it

  6. Nick Says:

    You mean the AsyncPRocessIngLibrary ?
    You might want to check the date this post was written…

  7. jason Says:

    Thanks for the Apr 1st joke, but you almost got me until I saw the “4/1”.

  8. Justin Says:

    Boo. Just wasted 2 minutes of my life.

Leave a Reply