4

This question addresses how to conditionally include code based on iOS version. But how does it work?

Suppose I set iOS Deployment Target to 3.2 in Xcode 4.5.2. In my code I put in some #ifdef statements:

#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0
  // Some iOS 4+ code
#endif

If I run the code on a 3.2 device, this code won't be there, but if I run it on a 4.3 device, it will, right? How does that happen? Or am I misunderstanding what's going on here?

Community
  • 1
  • 1
Ben Flynn
  • 18,524
  • 20
  • 97
  • 142
  • What's your goal here? Do you want to compile different code based on using different versions of Xcode or are you trying to write code for a single app that will run properly on devices with different versions of iOS? – rmaddy Nov 16 '12 at 03:59
  • Reading some SDK code. Since people will use it with different versions of XCode, given Bovinedragon's explanation, I can see why it's there. – Ben Flynn Nov 16 '12 at 17:05

1 Answers1

4

That is a compile time check so it will create the same behavior on any iOS version. Since the Deployment Target is less than 4.0 the code inside the if statement will not run on any device.

If you want the behavior you described you need to do a runtime check. You can see an example of how to do this in the thread that you linked.

Bovinedragon
  • 307
  • 1
  • 7