首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >比较xcode 7中的版本

比较xcode 7中的版本
EN

Stack Overflow用户
提问于 2015-09-09 01:57:46
回答 1查看 69关注 0票数 0

我有以下代码来比较当前版本和可用版本:

代码语言:javascript
复制
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");
    }

但是,当这些版本相同(0.1.2和0.1.2)时,它的写入量比当前版本要低。为什么会这样呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-09-09 03:06:13

web结果包含一个换行符。删除initWithData:...调用后的换行符和if语句之前的换行符:

代码语言:javascript
复制
avaliableVersion = [avaliableVersion stringByReplacingOccurrencesOfString:@"\n" withString:@""];
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32469789

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档