Before asking why: I'm writing an extension that observes the CFBundleVersion
of an app & then compares it to old version that isn't supported by the extension.
Here's what I do to compare.
CFStringRef _version = CFURLCreateStringByAddingPercentEscapes(NULL,
(__bridge CFStringRef)[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"],
NULL,
(CFStringRef)@" !*'();:@&=+$,/?%#[]",
kCFStringEncodingUTF8);
NSString *versionString = (NSString *)CFBridgingRelease(_version);
NSNumberFormatter * nsFormatter = [[NSNumberFormatter alloc] init];
[nsFormatter setNumberStyle:NSNumberFormatterDecimalStyle];
NSNumber * installedVersion = [nsFormatter numberFromString:versionString];
NSNumber * incompatibleVersion = [nsFormatter numberFromString:@"6.1.0"];
if (installedVersion <= incompatibleVersion) {
NSLog(@"This was triggered");
}
The code works great, but only when there are two decimals. For instance, if I set the CFBundleVersion
to 6.0
or 5.0
The code is not triggered. Is there a better way of comparing? I don't understand why it's thinking 5.0
is greater than 6.1.0
Suggestions?