版本號比較方法多樣但两,而且容易出問題迫吐,以前遇到過兩三次宰缤;以下代碼邏輯比較嚴密:
+ (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;
}