iOS检测新版本

2019-11-01  本文已影响0人  今年27
+(BOOL)hasNewVersionWithDictionary:(NSDictionary*)dictionary{

    NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
    
    NSNumber* resultCount = [dictionary objectForKey:@"resultCount"];
    if ([resultCount integerValue] > 0) {
        NSArray* array = [dictionary objectForKey:@"results"];
        NSDictionary* dic = [array firstObject];
        NSString* version = [dic objectForKey:@"version"];
        NSArray* versions = [version componentsSeparatedByString:@"."];
        //CFShow((__bridge CFTypeRef)(infoDic));
        NSString *currentVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];
        NSArray* currentVersions = [currentVersion componentsSeparatedByString:@"."];
        if ([versions[0] intValue] > [currentVersions[0] intValue]) {
            return YES;
        }else if ([versions[0] intValue] < [currentVersions[0] intValue]) {
            return NO;
        }else{
            if ([versions[1] intValue] > [currentVersions[1] intValue]) {
                return YES;
            }else if ([versions[1] intValue] < [currentVersions[1] intValue]){
                return NO;
                
            }else{
                if ([versions[2] intValue] > [currentVersions[2] intValue]) {
                    return YES;
                }else{
                    return NO;
                }
            }
        }
     
    }
    
    return NO;
    
}
上一篇下一篇

猜你喜欢

热点阅读