你好,歡迎來到IOS教程網

 Ios教程網 >> IOS訊息 >> 關於IOS >> app store版本比較算法

app store版本比較算法

編輯:關於IOS
- (BOOL)version:(NSString *)_oldver lessthan:(NSString *)_newver //系統api
{
    if ([_oldver compare:_newver option:NSNumbericSearch] == NSOrderedAscending)
    {
         return YES;
    }
    return NO;
}
- (BOOL)version:(NSString *)_oldver lessthan:(NSString *)_newver
{
    NSArray *a1 = [_oldver componentsSeparatedByString:@"."];
    NSArray *a2 = [_newver componentsSeparatedByString:@"."];
    
    for (int i = 0; i < [a1 count]; i++) {
        if ([a2 count] > i) {
            if ([[a1 objectAtIndex:i] floatValue] < [[a2 objectAtIndex:i] floatValue]) {
                return YES;
            }
            else if ([[a1 objectAtIndex:i] floatValue] > [[a2 objectAtIndex:i] floatValue])
            {
                return NO;
            }
        }
        else
        {
            return NO;
        }
    }
    return [a1 count] < [a2 count];
}

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved