Bar*_*cki 6 iphone objective-c ios c-preprocessor
我用它来检查iOS版本,但它不起作用:
#ifndef kCFCoreFoundationVersionNumber_iPhoneOS_5_0
#define kCFCoreFoundationVersionNumber_iPhoneOS_5_0 675.000000
#endif
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_5_0
#define IF_IOS5_OR_GREATER(...) \
if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iPhoneOS_5_0) \
{ \
__VA_ARGS__ \
}
#else
#define IF_IOS5_OR_GREATER 0
#endif
Run Code Online (Sandbox Code Playgroud)
我做的时候
#if IF_IOS5_OR_GREATER
NSLog(@"iOS5");
#endif
Run Code Online (Sandbox Code Playgroud)
什么都没发生.这里有问题吗?
Gow*_*iem 14
更简单:
#define IS_IOS6_AND_UP ([[UIDevice currentDevice].systemVersion floatValue] >= 6.0)
Run Code Online (Sandbox Code Playgroud)
定义此方法:
+(BOOL)iOS_5 {
NSString *osVersion = @"5.0";
NSString *currOsVersion = [[UIDevice currentDevice] systemVersion];
return [currOsVersion compare:osVersion options:NSNumericSearch] == NSOrderedAscending;
}
Run Code Online (Sandbox Code Playgroud)
然后将宏定义为该方法.
您已经定义了一个宏,但是您以非宏方式使用它.尝试这样的东西,使用相同的宏定义.
IF_IOS5_OR_GREATER(NSLog(@"iOS5");)
Run Code Online (Sandbox Code Playgroud)
(这不是你的#if/ #endifblock.)
| 归档时间: |
|
| 查看次数: |
26375 次 |
| 最近记录: |