比较Bundle版本

时间:2013-09-05 07:36:42

标签: ios compare version bundle

将应用程序上传到appStore时,Apple会检查Bundle Version是否高于现有版本。 我自己有这样做的方法吗?我正在通过Enterprise程序发布一个应用程序,并且我内置了一个检查新版本URL的机制。 目前我只是使用

if (![currentVersion isEqualToString:onlineVersion])

但这太粗糙了,因为如果版本较旧,它也会返回TRUE。

现在,意识到1.23.0> 1.3.0,我必须将组件中的版本分开,然后将每个本地组件与其相关的在线组件进行比较。

如果我必须这样做,我将不得不这样做,但我会认为有一个捷径。

任何?

2 个答案:

答案 0 :(得分:5)

这是苹果的方式

    updateAvailable = [newversion compare:currentversion options:NSNumericSearch] == NSOrderedDescending;

答案 1 :(得分:2)

好的,好的,我最终自己完成了这一切。抱歉这么懒。 我希望,这可以帮助某人,或者有人会指出一个明显的错误,或者愚蠢的低效率:

- (BOOL) compareBundleVersions: (NSString *) old to: (NSString *) new {
    NSMutableArray *oldArray = [[old componentsSeparatedByString:@"."] mutableCopy];
    NSMutableArray *newArray = [[new componentsSeparatedByString:@"."] mutableCopy];
    // Here I need to make sure that both arrays are of the same length, appending a zero to the shorter one
    int q = [oldArray count] - [newArray count];
    NSString *zero = @"0";
    if (q>0) {

        for (int i = 0; i < q; i++)
        {

            [newArray addObject:zero];
        }
    }
    if (q<0) {

        for (int i = 0; i < q*-1; i++)
        {

            [oldArray addObject:zero];
        }
    }

    for (int i = 0; i < [oldArray count]; i++)
    {
        if ([[oldArray objectAtIndex:i] intValue] < [[newArray objectAtIndex:i] intValue]) {

            return TRUE;
        }
    }

    return FALSE;
}
相关问题