0

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

if (![currentVersion isEqualToString:onlineVersion])

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

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

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

任何人?

4

2 回答 2

5

这是苹果的方式

    updateAvailable = [newversion compare:currentversion options:NSNumericSearch] == NSOrderedDescending;
于 2014-04-25T02:14:30.227 回答
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;
}
于 2013-09-05T10:00:35.827 回答