Tuesday, May 10, 2011

Objective C/Xcode 4: Check at runtime whether iOS device supports multitasking

Introduction


When I was recently in search for a code snippet that tells me whether the iOS device that the code is running does support Multitasking I quickly found some answers. All the answers seemed to be missing something though.

So below the solution I came up with, that satisfies all my requirements to check for multitasking of my iPhone/iPad/iPod device at runtime.

Difference between multitasking support of the SDK version and of the device version


Since version 4.0 iOS supports multitasking. Read more about it in this interesting article: Understanding iOS 4 Backgrounding and Delegate Messaging.

Even though you have iOS 4.x on your iPhone 3G it doesn't support multitasking. Multitasking is supported from iPhone 3GS and iPod touch G3 (both released in 2009) but not previous generations like iPhone 2G or 3G due to hardware limitations. Read more here: Apple announces multitasking for iPhone OS 4

The Code

//get the current device object
UIDevice* device = [UIDevice currentDevice];

//check if the currently running iOS knows the isMultitaskingSupport message (method)
if ([device respondsToSelector:@selector(isMultitaskingSupported)]){
        
        //check if the current device does actually support multitasking
        if ([device isMultitaskingSupported]) {
            //do some multitasking stuff

        } else {
            //deal with the lack of multitasking 

        }
        
    } else {
        //deal with the lack of multitasking 
    }

0 comments:

Post a Comment