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.
Example:
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
}
Recent Comments