[英]iOS/Objective-c: How to get a macro that says the version is higher or equal to 13.0 in the .h file?
I would like to have a macro that allows me to check the version or higher than the ios 13. I don't want to use that:我想要一个允许我检查版本或高于 ios 13 的宏。我不想使用它:
if (@available(iOS 13, *)) {
// iOS 13 (or newer) ObjC code
} else {
// iOS 12 or older code
}
Because the preprocessor will try to compile it and will not be able to do it.因为预处理器会尝试编译它而无法做到。 What I want is a macro that allows to compile properly without warning or errors message.我想要的是一个允许正确编译而没有警告或错误消息的宏。 Something like that:像这样的东西:
#ifdef __IPHONE_13_0
But I am not sure that line means 13.0 or higher.但我不确定那条线是否意味着 13.0 或更高版本。
My code in the.h is the following:我在.h 中的代码如下:
#ifdef __AVAILABILITY_INTERNAL__IPHONE_13_0
@property (nonatomic, retain) UIViewController *popoverController;
#else
@property (nonatomic, retain) UIPopoverController *popoverController;
#endif
It doesn't work.它不起作用。 How to check in the.h file the version of the ios?如何在 .h 文件中查看 ios 的版本? I cannot use that as it is in the.h file:我不能像在 .h 文件中那样使用它:
#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
if (SYSTEM_VERSION_LESS_THAN(@"5.0")) {
// code here
}
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6.0")) {
// code here
}
What do you think?你怎么看?
EDIT: How to avoid to get the message for the ipads before a previous version?编辑:如何避免在以前的版本之前获得 ipad 的消息?
But you are allowed to use the preprocessor variables when defining your API但是在定义 API 时,您可以使用预处理器变量
@property (nonatomic, retain) UIViewController *viewController NS_DEPRECATED_IOS(2.0, 13.0);
@property (nonatomic, retain) UIPopoverController *popoverController API_AVAILABLE(ios(13.0));
same for methods方法相同
-(void)halleluja:(Evil)brain API_AVAILABLE(ios(13.0)) {
//do evil stuff with brain
}
do not forget, your Apps targeted system version is meant here.不要忘记,您的应用程序目标系统版本是指这里。
You will find plenty of different variations on how to in the documentations of (upper file part)您会在(上部文件部分)的文档中找到许多不同的变体
#import "Availability.h" #import "可用性.h"
But you don't need to include it, Xcode does that for you.但是您不需要包含它,Xcode 会为您完成。
You can also tell your pre-compiler你也可以告诉你的预编译器
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_13
// code starting with ios(13.0)
[self halleluja:nope];
#else
// code earlier ios(13.0)
[self halleluja:papa]; //as defined above should throw a warning
#endif
and finally you can ask at runtime最后你可以在运行时询问
if ([[[UIDevice currentDevice] systemVersion] isEqualToString:@"13.0"]) {
// code only on ios(13.0) and only ios(13.0)!
}
or或者
NSString *versionString = [[UIDevice currentDevice] systemVersion];
if ([versionString floatValue] >= 13.0) {
// not sexy - but works.
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.