iOS本地版本和服务器对比

- (BOOL)canShowUpdate:(NSString *)localVersion onlineVersion:(NSString *)onlineVersion
{
    if (![localVersion isEqualToString:onlineVersion]) {
 
        NSArray *localArray = [localVersion componentsSeparatedByString:@"."];
        NSArray *onlineArray = [onlineVersion componentsSeparatedByString:@"."];
        
        NSUInteger length = localArray.count < onlineArray.count ? localArray.count : onlineArray.count;
        
        for (NSUInteger index = 0 ; index < length; index++) {
            if ([onlineArray[index] integerValue] > [localArray[index] integerValue] ) {
                if(index >= 1){
                    if ([onlineArray[index - 1] integerValue] >= [localArray[index - 1] integerValue]) {
                        return YES;
                    }
                } else {
                    return YES;
                }
            }
        }
        
        if (onlineArray.count > localArray.count) {
            return YES;
        }
    }
    return NO;
}

  

posted @ 2017-04-19 14:49  CodingTom  阅读(185)  评论(0编辑  收藏  举报