Adaptation to different iOS versions (# ifdef _ IPHONE_7_0)
Partial reference http://www.cnblogs.com/ios8/p/ios-version-com.html
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 (preprocessing, compilation, and running are not nonsense here)
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
Note that header files must be added.
#import
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 #define __IPHONE_5_0 50000 #define __IPHONE_5_1 50100 #define __IPHONE_6_0 60000 #define __IPHONE_6_1 60100 #define __IPHONE_NA 99999 /* not available */
While sdk7.0 has one more line.
#define __IPHONE_7_0 60100
The same is true for iOS8.
Note the following when using the framework or.:
Because when compiling the framework or. a depends on the compiling environment at that time. For example, you can use the iOS6 sdk to set the framework or. a is successfully compiled, but the sdk and framework or. the sdk of a is consistent and must be added to the runtime judgment ([[UIDevice currentDevice] systemVersion] floatValue)
Note:
1. If the sdk is compiled with a lower version (such as iOS6) and the final application is installed on the device of the later version (the iOS 7 system), no problem will occur, because iOS7 is compatible with iOS6, it cannot use the new features unique to iOS7, because the code is blocked.
2. If the sdk is compiled with a higher version (such as iOS7), install the final application on the device of the lower version (iOS6 system ), in this case, if you do not add it to the runtime, the problem may occur (possibly crash ). Because the application itself is compiled with iOS7 and uses the new functions provided by iOS7, the device does not support iOS7.
The write may be a bit messy. It is used for self-recorded purposes only.