版本号比较方法多样,而且容易出问题,以前遇到过两三次;以下代码逻辑比较严密:
+ (BOOL) canUpateLocationVersion:(NSString*)locationVersion serviceVersion:(NSString*)serviceVersion {
NSArray *locationArray = [locationVersion componentsSeparatedByString:@"."];
NSArray *serviceArray = [serviceVersion componentsSeparatedByString:@"."];
if (locationArray.count >= serviceArray.count) {
for (inti =0; i < serviceArray.count; i++) {
if ([locationArray[I] intValue] < [serviceArray[I] intValue]) {
return YES;
} else if ([locationArray[I] intValue] > [serviceArray[I] intValue]) {
return NO;
}
}
} else if (locationArray.count < serviceArray.count) {
for (int i =0; i < locationArray.count; i++) {
if ([locationArray[I] intValue] < [serviceArray[I] intValue]) {
return YES;
} else if ([locationArray[I] intValue] > [serviceArray[I] intValue]) {
returnNO;
}
}
if([serviceArray[locationArray.count]intValue] >0) {
returnYES;
}
}
return NO;
}
网友评论