Skip to content

Instantly share code, notes, and snippets.

@karajanyp
Forked from brownsoo/checking-ios-version.txt
Last active May 22, 2018 09:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karajanyp/14b8cc1b2b7840955d10a3f037300af0 to your computer and use it in GitHub Desktop.
Save karajanyp/14b8cc1b2b7840955d10a3f037300af0 to your computer and use it in GitHub Desktop.
Checking iOS version in above 8.0
NSString *getBuildVersion(NSString *textToBeSearch)
{
//the pattern to search for
//the \. escapes the . in regex. but the \ needs to be escaped in objective c
//thus \\.
NSString *pattern = @"Build (.*)\\)";
//capture any errors when creating the NSRegularExpression Object
NSError *error = nil;
//create a regex object using our pattern and options.
//we set the options to perform a case insensitive search
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:pattern options:NSRegularExpressionCaseInsensitive error: &error];
NSRange range = NSMakeRange(0, textToBeSearch.length);
if(regex == nil){//handle errors
return nil;
} else {
NSTextCheckingResult *match = [regex firstMatchInString:textToBeSearch options:0 range:range];
NSRange capture_range = [match rangeAtIndex:1]; //get the first matched group
// NSLog(@"Name: %@", [textToBeSearch substringWithRange:capture_range]);
return [textToBeSearch substringWithRange:capture_range];
}
}
int main(int argc, char *argv[])
{
//NSOperatingSystemVersion ios_10 = (NSOperatingSystemVersion){.majorVersion = 10, .minorVersion = 0, .patchVersion = 0};
NSOperatingSystemVersion ios8_0_1 = (NSOperatingSystemVersion){8, 0, 1};
if ([[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:ios8_0_1]) {
// iOS 8.0.1 and above logic
} else {
// iOS 8.0.0 and below logic
}
NSString *versionString = [[NSProcessInfo processInfo] operatingSystemVersionString];
NSString *buildVersionString = getBuildVersion(versionString);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment