How to verify the existence of a constant when creating a universal binary iPhone

I am trying to create a universal binary file that supports multitasking on iPhone 4 and can still work on iPad.

I know how to avoid compilation errors for different versions of iPhone IOS by checking if a class exists using NSClassFromString and "responseToSelector", but is there a way to check for constants like UIBackgroundTaskInvalid?

Of course, I can use #IFDEF, but I want to avoid this.

+2
source share
3 answers

You do it like this:

if (NULL != &UIBackgroundTaskInvalid) {
   //do multitasking stuff here
} else {
   // don't do multitasking stuff here.
}

Basically you want to check if the address of this variable exists.

. , #ifdef , SDK, .

+2

, , , , , .

+1

iOS , UIDevice isMultitaskingSupported, :

//----------------------------------------------------------------------
// returns YES if multitasking is available (iOS 4.0 or >)
//----------------------------------------------------------------------
BOOL hasMultitasking() 
{
    UIDevice* device = [UIDevice currentDevice];
    if ([device respondsToSelector:@selector(isMultitaskingSupported)]) {
        return [device isMultitaskingSupported];
    }
    return NO;
}

, , .

+1

All Articles