zoukankan      html  css  js  c++  java
  • iOS 版本更新

    版本号比较,如下:

    - (BOOL)compareVersionWithRemoteV:(NSString *)remoteStr localV:(NSString *)localStr {
        // 如果版本号相同,直接返回NO
        if ([remoteStr isEqualToString:localStr]) {
            return NO;
        }
        
        NSMutableArray *remoteArr = [[NSMutableArray alloc] init];
        NSMutableArray *locatArr = [[NSMutableArray alloc] init];
        [remoteArr addObjectsFromArray:[remoteStr componentsSeparatedByString:@"."]];
        [locatArr addObjectsFromArray:[localStr componentsSeparatedByString:@"."]];
        
        NSInteger maxLen = remoteArr.count;
        if (remoteArr.count < locatArr.count) {
            maxLen = locatArr.count;
        }
        
        while (remoteArr.count < maxLen) {
            [remoteArr addObject:@"0"];
        }
        while (locatArr.count < maxLen) {
            [locatArr addObject:@"0"];
        }
        
        for (int i = 0; i < maxLen; i++) {
            NSString *remote = remoteArr[i];
            NSString *local = locatArr[i];
            
            if (remote.intValue > local.intValue) {
                return YES;
            } else if (remote.intValue < local.intValue) {
                return NO;
            }
        }
        return NO;
    }

    调用判断

    1     BOOL isUpdate = [self compareVersionWithRemoteV:@"2.0" localV:@"2.0.1"];
    2     NSLog(@"%@",isUpdate ? @"有更新":@"无更新");
    用最好的情绪做最好的自我。开心是一天,不开心也是一天,不如天天开心。活在当下,生活就为你歌唱。
  • 相关阅读:
    JS_判断浏览器.
    JQ_使用AJAX获取SINA股票代码
    Struts2中的OGNL详解
    CSS原理与CSS经验分享
    Struts 与 Velocity 的集成
    30条HTML代码编写指南 for入门者
    OGNL使用小结
    Visual C++ 6.0 插件系列介绍
    C语言编译过程总结详解
    Web.xml配置详解
  • 原文地址:https://www.cnblogs.com/lukunlun/p/13785999.html
Copyright © 2011-2022 走看看