#define currentVersion [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]
#pragma mark--判断版本号是不是大于本地版本
-(BOOL)compareVesionWithServerVersion:(NSString *)version{
NSArray *versionArray = [version componentsSeparatedByString:@"."];//服务器返回版
NSArray *currentVesionArray = [currentVersion componentsSeparatedByString:@"."];//当前版本
NSInteger a = (versionArray.count> currentVesionArray.count)?currentVesionArray.count : versionArray.count;
if ([version isEqualToString:currentVersion]) {
return NO;
}
for (int i = 0; i< a; i++) {
NSInteger a = [[versionArray objectAtIndex:i] integerValue];
NSInteger b = [[currentVesionArray objectAtIndex:i] integerValue];
if (a > b) {
// NSLog(@"有新版本");
return YES;
}else if(a < b){
return NO;
}
}
if (versionArray.count > currentVesionArray.count) {
return YES;
}
if (versionArray.count < currentVesionArray.count ) {
return NO;
}
return NO;
}
网友评论