Sometimes in a project to be compatible with a low-version iOS system, it is common to write different code for different OS versions, such as:
#define Is_ios7_or_later ([[Uidevice currentdevice].systemversion Floatvalue] >=7.0) if (is_ios7_or_later) { [[ Uinavigationbar appearance] Setbartintcolor:[uicolor Standardlightgray];//ios7 when api}else{ [[ Uinavigationbar appearance] Settintcolor:[uicolor Standardlightgray];}
This code compiles on the xcode5/xcode6 is no problem, but the compilation on the xcode4.6 can not pass, because this if/else to run time to know whether the condition is established, in the code compile is not known. This can be handled:
#define Is_ios7_or_later ([[Uidevice currentdevice].systemversion Flo Atvalue] >=7.0) #ifdef __iphone_7_0 Span style= "color: #0000ff;" >if (Is_ios7_or_later) {[[Uinavigationbar appearance] Setbartintcolor:[uico Lor Standardlightgray]]; else {[[Uinavigationbar Appearan CE] settintcolor:[uicolor Standardlightgray]]; #else [[Uinavigationbar appearance] Settintcolor:[uicolor Standardlightgray]]; #endif
__iphone_7_0 is a system macro that can be determined at compile time if it has no definition. In this case, the code can be compiled successfully on XCODE4.6/XCODE5/XCODE6.
But if you compile on xcode4.6 (IOS6), the compile-time Xcode will put #ifdef~ #else之间的代码删除掉, will only compile #else~ #endif之间的代码, and eventually your project for the high version of iOS code will not be executed, Even if you are running the program on a IOS8 phone.
So if you want to be compatible with both high and low versions of iOS, use a higher version of Xcode to compile your code, and if you want your project to compile on a lower version of Xcode, use the above macro in your code to differentiate the iOS version.
Xcode code compilation issues for different iOS versions