Reputation: 58448
I've seen apps on the iPhone that if running on 3.0 will use 3.0 features/APIs such as the in-app email composer, and if running on 2.x not using those features, and exiting the app to launch Mail instead.
How is this done?
My initial thoughts were to use
#ifdef __IPHONE_3_0
but that will only work if I actually build the app against the 3.0 SDK - which then prevents it from running on 2.x phones.
Also, running with that thought, the app has to be linked against the 3.0 SDK anyway to get the 3.0 APIs...
I'm a little confused as to how it's been achieved.
Upvotes: 4
Views: 304
Reputation: 2046
You set the Base SDK to 3.0, and the Deployment Target to 2.2.
You then wrap all the 3.0-specific (or higher) methods in NSClassFromString and respondsToSelector statements.
It will work on the device in 2.2, but not in the simulator.
The advantage of this method is that you don't tie your code to specific version numbers - just whether the methods or classes exist or not.
This page explains it pretty well.
http://www.clarkcox.com/blog/2009/06/23/sdks-and-deployment-targets/
Upvotes: 5
Reputation: 9507
You can test for the current version of the OS at runtime using:
float version = [[[UIDevice currentDevice] systemVersion] floatValue];
if (version >= 3.0)
Which will let you use certain API calls at runtime if available.
This question has some other details for how to compile in specific things per API version.
Upvotes: 0