Skip to content

Instantly share code, notes, and snippets.

@danthorpe
Created June 25, 2012 12:13
Show Gist options
  • Save danthorpe/2988246 to your computer and use it in GitHub Desktop.
Save danthorpe/2988246 to your computer and use it in GitHub Desktop.
Helper functions for applying code between different iOS versions at runtime.
//
// DeviceHelper.h
//
// Created by Daniel Thorpe on 25/06/2012.
// Copyright (c) 2012 Blinding Skies Limited. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface DeviceHelper : NSObject
+ (void)iOS4OrNewer:(void(^)(void))shiny older:(void(^)(void))old;
+ (void)iOS5OrNewer:(void(^)(void))shiny older:(void(^)(void))old;
+ (void)iOS6OrNewer:(void(^)(void))shiny older:(void(^)(void))old;
@end
//
// DeviceHelper.m
//
// Created by Daniel Thorpe on 25/06/2012.
// Copyright (c) 2012 Blinding Skies Limited. All rights reserved.
//
#import "DeviceHelper.h"
typedef NS_ENUM(NSUInteger, iOSMajorVersions) {
iOSMajorVersion4 = 4,
iOSMajorVersion5 = 5,
iOSMajorVersion6 = 6
};
@implementation DeviceHelper
+ (void)iOS4OrNewer:(void(^)(void))shiny older:(void(^)(void))old {
[DeviceHelper major:iOSMajorVersion4 orNewer:shiny older:old];
}
+ (void)iOS5OrNewer:(void(^)(void))shiny older:(void(^)(void))old {
[DeviceHelper major:iOSMajorVersion5 orNewer:shiny older:old];
}
+ (void)iOS6OrNewer:(void(^)(void))shiny older:(void(^)(void))old {
[DeviceHelper major:iOSMajorVersion6 orNewer:shiny older:old];
}
+ (void)major:(iOSMajorVersions)threshold orNewer:(void(^)(void))shiny older:(void(^)(void))old {
// Get the major system OS version
NSInteger major = [[[[UIDevice currentDevice] systemVersion] substringToIndex:1] integerValue];
if (major >= threshold) {
if (shiny) shiny();
} else {
if (old) old();
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment