Created
June 25, 2012 12:13
-
-
Save danthorpe/2988246 to your computer and use it in GitHub Desktop.
Helper functions for applying code between different iOS versions at runtime.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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