4 回答
TA贡献1818条经验 获得超8个赞
快速回答…
#available
if
guard
if #available(iOS 9, *) {}
[[NSProcessInfo processInfo] operatingSystemVersion]
if (@available(iOS 9, *)) {}
完整答案…
检查是否存在API:
UIPopoverController
NSClassFromString
:
if (NSClassFromString(@"UIPopoverController")) { // Do something }
if ([LAContext class]) { // Do something }
CLLocationManager
UIDevice
if ([CLLocationManager headingAvailable]) { // Do something }
检查符号的存在:
UIApplicationOpenSettingsURLString
-openURL:
if (&UIApplicationOpenSettingsURLString != NULL) { [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]; }
与操作系统版本相比:
NSProcessInfo
- (BOOL)isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion)version
systemVersion
UIDevice
// A system version of 3.1 or greater is required to use CADisplayLink. The NSTimer // class is used as fallback when it isn't available. NSString *reqSysVer = @"3.1"; NSString *currSysVer = [[UIDevice currentDevice] systemVersion]; if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending) { displayLinkSupported = TRUE; }
systemVersion
TA贡献1812条经验 获得超5个赞
/* * System Versioning Preprocessor Macros */ #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) /* * Usage */ if (SYSTEM_VERSION_LESS_THAN(@"4.0")) { ... } if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"3.1.1")) { ... }
TA贡献1818条经验 获得超7个赞
您可以使用NSFoundationVersionNumber
,从NSObjCRuntime.h
头文件。
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) { // here you go with iOS 7 }
- 4 回答
- 0 关注
- 742 浏览
添加回答
举报