Rule 1: Do not depend on version or device type to determine if a feature is available. Different devices (iPhone, iPod Touch and iPad) can get the same feature but at different versions of the OS.
Link weakly against frameworks and missing classes will be nil
. Or use NSClassFromString()
function that also returns nil
if a class do not exist. Also use -[NSObject respondsToSelector:]
to query if a method exists or not.
Rule 2: Apple discourages from using the defined constants (such as __IPHONE_2_2
) when checking for versions, instead use their numerical values as such:
#if (__IPHONE_OS_VERSION_MAX_ALLOWED >= 40200)
NSLog(@"BUILT against iPhone 4.2 or later");
#endif
But do take notice using #if
compile-time directive will only check what version of the SDK you build against not which version of the OS will later run on.