tags:

views:

95

answers:

2

What is the difference between

__IPHONE_OS_VERSION_MAX_ALLOWED

and

__IPHONE_OS_VERSION_MIN_REQUIRED

Which should I use to detect old/new SDKs, like

#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_3_2
+1  A: 

Definitely use __IPHONE_OS_MIN_REQUIRED, because that allows you to check system versions which may not include certain APIs that are available in later versions.

Speaking of which, you might as well use [[UIDevice currentDevice] systemVersion] ;)

Jacob Relkin
+2  A: 

__IPHONE_OS_VERSION_MIN_REQUIRED is set to the Deployment target, which represents the version the user must minimally run to install your app. __IPHONE_OS_VERSION_MAX_ALLOWED is set to the SDK version you're compiling against, although that doesn't mean your app won't run on newer versions though, but you can use it to check whether some OS features are available.

For instance, since iOS 3.2 we have the UIBezierPath class. If you're compiling against SDK 3.1 (to test it in the iPhone Simulator presumably), this new class is not available so the compiler will give you a warning that the class doesn't exist. Fair enough, but we don't want to comment that specific code every time we build it against the older SDK, just for a simulator test. We just want to hide these blocks of code and that's made possible by those macro's.

Please read this article on Cocoa with Love for further explanation, tips and tricks.

JoostK
But what about __IPHONE_OS_VERSION_MAX_ALLOWED (not "_REQUIRED")?
Konstantin
Whoops, I meant MAX_ALLOWED, there is no MAX_REQUIRED defined at all.
JoostK