Reputation: 642
I have this code to compare current and available version:
NSString *currentVersion = [[NSString alloc]initWithFormat:@"%@", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]];
NSError *error = nil;
NSData *avaliableVersionData = [NSData dataWithContentsOfURL:[NSURL URLWithString:
@"http://update.blockade.tech/current-version"] options:0 error:&error];
NSString *avaliableVersion = [[NSString alloc]initWithData:avaliableVersionData encoding:NSUTF8StringEncoding];
if ([avaliableVersion compare:currentVersion options:NSNumericSearch] == NSOrderedDescending) {
NSLog(@"lower");
} else {
NSLog(@"ok");
}
But when those versions are same(0.1.2 and 0.1.2), it write than current version is lower. Why is it?
Upvotes: 0
Views: 73
Reputation: 1491
The web result contains a newline. Strip out the newline after the initWithData:...
call and before the if
statement with:
avaliableVersion = [avaliableVersion stringByReplacingOccurrencesOfString:@"\n" withString:@""];
Upvotes: 1