You can use this method or the one that DarkDust says and check IOS SDK version when you are compiling, but typically what's nicer is if you handle some of this stuff at runtime since users can update their device and then magically adopt new features or get better OS integration.
There are a couple of ways of doing this. In newer SDKS you should have NS_CLASS_AVAILABLE
. However, if you are still supporting older SDKs you may not. But this is objective-c, so luck is on our side:
Class cls = NSClassFromString (@"NSRegularExpression");
if (cls) {
// Create an instance of the class and use it.
} else {
// Alternate code path to follow when the
// class is not available.
}
Basically the way this works is asks the type system if a class is available, if not, it returns null. This is somewhat dangerous if left untested because it is a string and will compile, but you should be able to handle it.
If it's a class that exists in both places, you can test selector availability at runtime like this:
if( [TheAppleClass instancesRespondToSelector:@selector(aMethod:)] ) {
// invoke the inherited method
[myInstance aMethod:parameter];
}
reference1 reference2
By doing this you could provide a build that still supports OS4.2 users with a custom tweet sheet, but when they upgrade, they automatically get the OS twitter integration. But, it's still all in a single build you can release when you want without having to wait for 90% of the market to update before you start alienating older OS users.