TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Dec 2014 |
Maintained by Yan Rabovik.
Most common environment checks in one place. Pull Requests are welcome.
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
}
Detect new iOS 7 flat UI mode:
if (RSEnvironment.UI.isFlatMode){
// ...
}
UI idioms:
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
}
Detecting specific model:
if (RSEHardwareModelIPhone5s == RSEnvironment.hardware.model){
// iPhone5s-only code
}
App's version:
NSString *appStoreVersion = @"2.19.0";
if ([RSEnvironment.app.version isLessThan:appStoreVersion]){
NSLog(@"An update available!");
}
Some abstract versions:
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
Runtime checks for deployment target and base SDK are also available if needed:
if ([RSEnvironment.deploymentTarget.version isLessThan:@"6.0"]){
// ...
}
NSLog(@"%@",RSEnvironment.baseSDK.version.string); // 7.0.0
NSLog(@"%@",RSEnvironment.description);
Sample output:
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 on twitter)
MIT License.