我想为我的项目做一个小的定义。该定义应该只是执行代码,如果它在ios版本之上。看起来像这样
#define IF_OS_8_OR_LATER(CODE) \
if([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) \
{ \
CODE; \
}
它很简单,适合这种东西
IF_OS_8_OR_LATER(_locationManager.allowsBackgroundLocationUpdates = YES);
但是现在我想扩展它以避免在部署目标中不可用"我的IDE(AppCode)中的警告。我想把它扩展到这个
#define IF_OS_8_OR_LATER(CODE) \
_Pragma("clang diagnostic push") \
_Pragma("ide diagnostic ignored \"UnavailableInDeploymentTarget\"") \
if([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) \
{ \
CODE; \
} \
_Pragma("clang diagnostic pop")
但不幸的是,这不起作用。有什么建议如何实现这个?
答案 0 :(得分:0)
如果您根本不需要此警告(也在其他文件中),您只需在首选项中禁用此检查 - >检查 - > Objective-C - >一般 - > API的使用对于部署目标不可用。
如果要为单个文件禁用此警告 - 您可以将光标放在该行上,按Alt + Enter(将打开上下文菜单),点击键盘上的“右箭头”键或小三角形在使用鼠标的上下文菜单选项右侧 - 它将打开上下文菜单,其中包含“Supress for file”选项。您可以选择此选项,它将插入所需的指令。
如果您想手动执行此操作,以下代码段应该适用于您:
#pragma clang diagnostic push
#pragma ide diagnostic ignored "UnavailableInDeploymentTarget"
#define IF_OS_8_OR_LATER(CODE) \
if([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) \
{ \
CODE; \
}
#pragma clang diagnostic pop
答案 1 :(得分:-1)
You should write like this:
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_8_0
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound)];
#endif
Hope this helps you...