tags:

views:

50

answers:

1

As my iPhone app can run on both OS 3 and 4, I need a way to safely test for iOS 4 SDK features.

I like to avoid checking the [UIDevice ... systemVersion] string (I wonder why Apple failed to provide a numeric value here for easy testing, as it's available on OS X).

Anyway. The usual clean way to test for SDK features is to check if a class reponds to a selector, like this:

if ([UIApplication instancesRespondToSelector:...

And for C methods, one simply checks if the function pointer is NULL:

if (newFunction != NULL) ...

But my problem is that I need to check if a global variable exists. E.g. this one:

extern NSString *const UIApplicationDidEnterBackgroundNotification __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_0);

Any idea how one can test their existence at runtime?

+1  A: 

Hi,

the default method is

UIDevice* device = [UIDevice currentDevice];

BOOL backgroundSupported = NO;

if ([device respondsToSelector:@selector(isMultitaskingSupported)])

backgroundSupported = device.multitaskingSupported;

When the test is passed your "it exists in 4.x" global variable shoudl be available.

By the way - it answers if OS4 is there an if the device supports multitasking. Manfred

ManniAT
Thanks for that hint towards device.multitaskingSupported. I had not been aware of it.My question was more general, though, not specific to this particular feature. I like to know if there's a way to test for declared globals.
Thomas Tempelmann