Compatibility with different versions of IOS Development 2 (# ifdef _ IPHONE_7_0)

Source: Internet
Author: User
Tags one more line

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.

 

  1. 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.

 

  1. If ([[[UIDevice currentDevice] systemVersion] floatValue]> = 7.0 ){
  2. Self. window. tintColor = [UIColor redColor];
  3. }


In this case, you can only add a pre-processing statement to write the statement as follows:

 

  1. # Ifdef _ IPHONE_7_0
  2. If ([[[UIDevice currentDevice] systemVersion] floatValue]> = 7.0 ){
  3. Self. window. tintColor = [UIColor redColor];
  4. }
  5. # 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

 

  1. # Define _ IPHONE_2_0 20000
  2. # Define _ IPHONE_2_1 20100
  3. # Define _ IPHONE_2_2 20200
  4. # Define _ IPHONE_3_0 30000
  5. # Define _ IPHONE_3_1 30100
  6. # Define _ IPHONE_3_2 30200
  7. # Define _ IPHONE_4_0 40000
  8. # Define _ IPHONE_4_1 40100
  9. # Define _ IPHONE_4_2 40200
  10. # Define _ IPHONE_4_3 40300
  11. # Definely _ IPHONE_5_0 50000
  12. # Define _ IPHONE_5_1 50100
  13. # Definely _ IPHONE_6_0 60000
  14. # Define _ IPHONE_6_1 60100
  15. # Define _ IPHONE_NA 99999/* not available */


While sdk7.0 has one more line.

  1. # Depin__ IPHONE_7_0 60100


So ...... I don't want to explain much ......

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.