Let's talk about the adaptation between different ios versions.
Let's talk about one thing first: In xcode, there is one thing called targets. Apple's official documentation says this:
A target specifies a product to build and contains the instructions for building the product from a set of files in a project or workspace. A target defines a single product; it organizes the inputs into the build system-the source files and instructions for processing those source files-required to build that product. projects can contain in one or more targets, each of which produces one product. (omitted)
A simple translation is a target that details the product to be built, including instructions in a file in a project or working directory. It seems that it is still unclear. I searched on Google and found that the explanation of target is good:
A target basically defines what it is you are building and how you are building it. you can add more targets if you wowould like to build more than one thing. this usually makes sense if you need to build several related things from the same project. for instance, you might want one target for a full, paid version of an application, and another target for a reduced, free version of an application. both targets wocould include much of the same code and resources, but some of the settings wocould be different and you might have different files encoded with each.
This means that if you want to divide an application into a paid full version and a free simplified version, most of the Code for these two versions will be the same, only the individual settings and included files are different, you can create an application and get two targets corresponding to two versions.
The following is a simple example to illustrate the adaptation problem between iOS7.0 and iOS6.1 (and earlier versions) (xcode5.0 is used and there are two versions of sdk 6.1 and 7.0)
Create a new project. The default development target, base sdk, and simulator versions are both 7.0. In AppDelegate, write down the didfinishlaunchingwitexceptions method.
- Self. window. tintColor = [UIColor redColor];
Then run it. There is no error. Next, we will change the development target, base sdk, and simulator versions to 6.1 (note that xcode does not have a 6.1 sdk by default, and you need to import it separately ). Then, an error is reported:
That is to say, the tintColor attribute is not rooted in iOS6.1, and an error occurs during compilation. At this time, it is useless to add the judgment statement as follows, so an error is reported.
- If ([[[UIDevice currentDevice] systemVersion] floatValue]> = 7.0 ){
- Self. window. tintColor = [UIColor redColor];
- }
In this case, you can only add a pre-processing statement to write the statement as follows:
- # Ifdef _ IPHONE_7_0
- If ([[[UIDevice currentDevice] systemVersion] floatValue]> = 7.0 ){
- Self. window. tintColor = [UIColor redColor];
- }
- # Endif
In this way, no error will be reported after compilation ...... This is because there is an Availability. h file under usr/include under sdk6.1, which defines a lot of macros, including
- # Define _ IPHONE_2_0 20000
- # Define _ IPHONE_2_1 20100
- # Define _ IPHONE_2_2 20200
- # Define _ IPHONE_3_0 30000
- # Define _ IPHONE_3_1 30100
- # Define _ IPHONE_3_2 30200
- # Define _ IPHONE_4_0 40000
- # Define _ IPHONE_4_1 40100
- # Define _ IPHONE_4_2 40200
- # Define _ IPHONE_4_3 40300
- # Definely _ IPHONE_5_0 50000
- # Define _ IPHONE_5_1 50100
- # Definely _ IPHONE_6_0 60000
- # Define _ IPHONE_6_1 60100
- # Define _ IPHONE_NA 99999/* not available */
While sdk7.0 has one more line.
- # Depin__ IPHONE_7_0 60100
So ...... I don't want to explain much ......