I\'d like build a game for both the iPhone and iPad. As such, it would make sense to start this project from scratch as a universal app. However, iPhone and iPad currently run
You mainly need to do two things:
To do the first, right-click on your target and select “Get Info.” The frameworks are listed in the inspector (under the “General” tab) with a drop-down box next to them that’ll allow you to select “Weak” linking. This ensures that the app will still run if the framework is not present.
To do the second, you could do something like the following to test for the new block-based animation in iOS 4:
if ([UIView respondsToSelector:@selector(animateWithDuration:animations:)]) {
// Your awesome animation code here
} else {
// Your almost-as-awesome, non-block-based animation code here.
}
By using introspective methods such as -respondsToSelector:
, you can avoid calling something that the currently-running OS doesn’t support.
Note also that if you wanted to support iPhone OS 3.0, these same rules would apply.
Finally, it's also possible—though not advisable—to do this like so:
#ifdef __IPHONE_4_0
// Your iOS 4.0-compatible code here
#elif defined(__IPHONE_3_2)
// Your iPhone OS 3.2-compatible code here
#elif defined(__IPHONE_3_0)
// Your iPhone OS 3.0-compatible code here
#endif
Why is this not advisable? Simple: only the code for the highest-numbered iOS version will be compiled. iPhone apps aren’t compiled separately for separate iOS versions, so to get this to actually work, you would have to release multiple versions of the app.