Using iPhone OS 3.0 features, if available, and 2.1 features, if not, in a single executable file

I saw applications on the iPhone that if version 3.0 uses 3.0 functions / APIs such as the email linker in the application, and if you use 2.x without using these functions, then exit the application to start Mail instead.

How it's done?

My initial thoughts were to use

#ifdef __IPHONE_3_0 

but this will only work if I really create an application against the 3.0 SDK, which will prevent it from running on 2.x phones.
In addition, working with this thought, the application must be connected to the SDK 3.0 in any case in order to get the 3.0 API ...

I am a little confused as to how this was achieved.

+4
source share
2 answers

You install the base SDK at 3.0, and the target deployment level is 2.2.

Then you complete all 3.0-specific (or higher) methods in the NSClassFromString and respond to the ToSelector instructions.

It will work on the device in 2.2, but not in the simulator.

The advantage of this method is that you do not bind your code to specific version numbers - are there just methods or classes.

This page explains it pretty well.

http://www.clarkcox.com/blog/2009/06/23/sdks-and-deployment-targets/

+5
source

You can check the current OS version at runtime using:

 float version = [[[UIDevice currentDevice] systemVersion] floatValue]; if (version >= 3.0) 

Which allows you to use certain API calls at run time, if available.

There is another piece of information on how to compile certain things for each version of the API.

0
source

All Articles