rabovik / RSEnvironment

Most common environment checks in one place: system version, retina support, UI flat mode, device models and so on.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RSEnvironment

Most common environment checks in one place. Pull Requests are welcome.

Usage

Detect iOS version

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
}

UI modes

Detect new iOS 7 flat UI mode:

if (RSEnvironment.UI.isFlatMode){
    // ...
}

UI idioms:

if (RSEnvironment.UI.isIdiomIPad){
    // ...
}

Detect screen properties

if (RSEnvironment.screen.is4InchSize){
    // iPhone 5+ screen size
}
if (RSEnvironment.screen.isRetina){
    // ...
}
NSLog(@"Scale: %f", RSEnvironment.screen.scale);

Hardware checks

if (RSEnvironment.hardware.isIPadMini){
    // The device is iPad Mini
}

Detecting specific model:

if (RSEHardwareModelIPhone5s == RSEnvironment.hardware.model){
    // iPhone5s-only code
}

Compare versions

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]){
    // ...
}

Check deployment target and Base SDK versions

#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

Get basic environment summary

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

CocoaPods

Add RSEnvironment to your Podfile.

Requirements

  • iOS 5.0+
  • ARC

Author

Yan Rabovik (@rabovik on twitter)

License

MIT License.

Acknowledgments

About

Most common environment checks in one place: system version, retina support, UI flat mode, device models and so on.

License:MIT License


Languages

Language:Objective-C 97.9%Language:Ruby 2.1%