tags:

views:

325

answers:

2

I assume it will just crash, right? If I develop an iPhone app that uses the iOS 4 SDKs and it makes it's way on into the app store, how can I ensure it doesn't get downloaded by a person running an older version of the iOS?

Thanks in advance for your help!

+2  A: 

If your project specifies 4.0 as the target then it won't even get loaded on the 3.2 phone - no problem.

When you publish an app to the store you specify the minimum OS level and acceptable devices (so you don't go looking for GPS on an iPod Touch, for example). There is a compatibility check that should prevent an app being loaded if it is not compatible. The App approval process (hopefully) makes sure that what you have said is compatible actually is.

If you somehow use APIs that don't exist on the device (because you are targeting a version prior to the introduction of that API or for any other reason) then yep, you'll get a crash due to unknown selector.

You can use

#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 30200

to check what version you are targeting... the first number (3) is the major revision, the third number (2) is the minor revision. Hence the check shown is for 3.2.

Adam Eberbach
+2  A: 

Rather than using Adam Eberbach's approach using compile time preprocessor directives to split your code, consider using run time checks like respondsToSelector:, using NSClassFromString checks against nil to determine if classes exist, and weak-linking to new frameworks and libraries.

This will allow you to write one app that can live on multiple devices without any code segregation or separate binaries.

Jasarien
does this result in code bloat, or worse, slower/heavier performance?
Jeff Meatball Yang
I believe the performance impacts are completely negligible... Depending on your definition of code bloat, I'd be inclined to disagree. It's a few lines here and there, that can be removed as and when you remove support for legacy OS's.
Jasarien
respondsToSelector is a very good way to do it, probably better than preprocessor.
Adam Eberbach