将最常见的环境检查集中在一个地方。欢迎提交Pull Requests。
if ([RSEnvironment.system.version isGreaterThanOrEqualTo:@"5.1"]){
// iOS 5.1+ code
}
if ([RSEnvironment.system.version isLessThan:@"6.1"]){
// ...
}
if ([RSEnvironment.system.version.major >= 7]){
// iOS 7+ code
}
检测新的iOS 7扁平UI模式
if (RSEnvironment.UI.isFlatMode){
// ...
}
UI约定
if (RSEnvironment.UI.isIdiomIPad){
// ...
}
if (RSEnvironment.screen.is4InchSize){
// iPhone 5+ screen size
}
if (RSEnvironment.screen.isRetina){
// ...
}
NSLog(@"Scale: %f", RSEnvironment.screen.scale);
if (RSEnvironment.hardware.isIPadMini){
// The device is iPad Mini
}
检测特定型号
if (RSEHardwareModelIPhone5s == RSEnvironment.hardware.model){
// iPhone5s-only code
}
应用的版本
NSString *appStoreVersion = @"2.19.0";
if ([RSEnvironment.app.version isLessThan:appStoreVersion]){
NSLog(@"An update available!");
}
一些抽象版本
NSString *version1 = @"3.0";
NSString *version2 = @"3.0.0";
if ([[RSEVersion versionWithString:version1] isGreaterThanOrEqualTo:version2]){
// ...
}
#if RS_DEPLOYMENT_TARGET_GREATER_THAN_OR_EQUAL(6,0,0)
// Compile 6.0+ code.
#endif
#if RS_BASE_SDK_LESS_THAN(7,0,0)
// Do not use features not available in SDK 6.
#endif
如果需要,提供对部署目标和基础SDK的运行时检查
if ([RSEnvironment.deploymentTarget.version isLessThan:@"6.0"]){
// ...
}
NSLog(@"%@",RSEnvironment.baseSDK.version.string); // 7.0.0
NSLog(@"%@",RSEnvironment.description);
示例输出
RSEnvironment:
app:
name: RSEnvironmentExample
version: 2.17.3
bundle ID: ru.rabovik.RSEnvironmentExample
system:
version: 5.1.1
UI:
isIdiomIPad: 1
isIdiomIPhone: 0
isFlatMode: 0
screen:
scale: 1.000000
isRetina: 0
size: 768x1024 points
resolution: 768x1024 pixels
is 4-inch screen: 0
hardware:
model name: iPad
model ID: iPad1,1
deploymentTarget:
version: 5.1.0
baseSDK:
version: 7.0.0
Yan Rabovik (@rabovik 在Twitter上)
MIT许可证。