-
-
Save karajanyp/14b8cc1b2b7840955d10a3f037300af0 to your computer and use it in GitHub Desktop.
Checking iOS version in above 8.0
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
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