This is a draft.
Runtime check of iOS version installed on the device
UIDevice systemVersion
[[UIDevice currentDevice] systemVersion];
NSUInteger DeviceSystemMajorVersion(void)
{
static NSUInteger deviceSystemMajorVersion = -1;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
deviceSystemMajorVersion = [[[[[UIDevice currentDevice] systemVersion] componentsSeparatedByString:@"."] objectAtIndex:0] intValue];
});
return deviceSystemMajorVersion;
}
Xcode 5 + iOS 6 device = 6
Xcode 5 + iOS 7 device = 7
Xcode 5 + iOS 8 device = 8
Xcode 6 + iOS 6 device = 6
Xcode 6 + iOS 7 device = 7
Xcode 6 + iOS 8 device = 8
NSFoundationVersionNumber
These are defined in the Foundation framework, file NSObjCRuntime.h.
#define NSFoundationVersionNumber_iOS_5_0 881.00
#define NSFoundationVersionNumber_iOS_5_1 890.10
#define NSFoundationVersionNumber_iOS_6_0 992.00
#define NSFoundationVersionNumber_iOS_6_1 993.00
#define NSFoundationVersionNumber_iOS_7_0 1047.20
#define NSFoundationVersionNumber_iOS_7_1 1047.25
Xcode 5 + iOS 6.1.3 device = 993.00
Xcode 5 + iOS 7.1.2 device = 1047.25
Xcode 5 + iOS 8.0.2 device = 1140.11
Xcode 6 + iOS 6.1.3 device = 993.00
Xcode 6 + iOS 7.1.2 device = 1047.25
Xcode 6 + iOS 8.0.2 device = 1140.11
kCFCoreFoundationVersionNumber
These are defined in the CoreFoundation framework, file CFBase.h.
#define kCFCoreFoundationVersionNumber_iOS_5_0 675.00
#define kCFCoreFoundationVersionNumber_iOS_5_1 690.10
#define kCFCoreFoundationVersionNumber_iOS_6_0 793.00
#define kCFCoreFoundationVersionNumber_iOS_6_1 793.00
#define kCFCoreFoundationVersionNumber_iOS_7_0 847.20
#define kCFCoreFoundationVersionNumber_iOS_7_1 847.24
Xcode 5.1.1 + iOS 6.1.3 device = 793.00
Xcode 5.1.1 + iOS 7.1.2 device = 847.27
Xcode 5.1.1 + iOS 8.0.2 device = 1140.10
Xcode 6 + iOS 6.1.3 device = 793.00
Xcode 6 + iOS 7.1.2 device = 847.27
Xcode 6 + iOS 8.0.2 device = 1140.10
iOS8
NSOperatingSystemVersion ios8_0_0;
ios8_0_0.majorVersion = 8;
ios8_0_0.minorVersion = 0;
ios8_0_0.patchVersion = 0;
if ([[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:ios8_0_0]) {
isAtLeastSDKVersion8 = YES;
}
Summary
Compile-time check of iOS version installed on the device
Hmm..
Let’s conclude that all checks for the installed version on the device the app currently is running must be done at runtime :)
Compile-time check of version linked against
__IPHONE_OS_VERSION_MAX_ALLOWED
is set to what the Base SDK is set to in the Xcode build settings for the target.
__IPHONE_OS_VERSION_MIN_REQUIRED
is set to what the iOS Deployment Target is set to in the Xcode build settings for the target.
These are assigned the value of a constant __IPHONE_X_Y
, where X is the major version and Y is the minor version. These are defined in Availability.h.
#define __IPHONE_5_0 50000
#define __IPHONE_5_1 50100
#define __IPHONE_6_0 60000
#define __IPHONE_6_1 60100
#define __IPHONE_7_0 70000
#define __IPHONE_7_1 70100
#define __IPHONE_8_0 80000
Note that if the main executable target is linking against a static library, these constants may not be equal between the executable target and the static library depending on the build settings for each project. For example __IPHONE_OS_VERSION_MIN_REQUIRED
could return __IPHONE_7_0
for the executable target and __IPHONE_6_0
for the static library target.
For example check this in code with preprocessor macros:
#if defined(__IPHONE_7_0) && (__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_7_0)
// The target where this code is running is compiled with
// the "Base SDK" Xcode build setting set to iOS 7 SDK or later.
#else
//
#endif
- Note that you must first check for the existance of
__IPHONE_7_0
before comparing with it. - Note that this is independent on the actual iOS installed on the device which is executing.