2025-10-20 09:43:10 +08:00
|
|
|
|
//
|
|
|
|
|
|
// QXAppVersionView.m
|
|
|
|
|
|
// QXLive
|
|
|
|
|
|
//
|
|
|
|
|
|
// Created by 启星 on 2025/9/27.
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
#import "QXAppVersionView.h"
|
|
|
|
|
|
#import "QXMineNetwork.h"
|
|
|
|
|
|
|
|
|
|
|
|
@interface QXAppVersionView()<UITextFieldDelegate>
|
|
|
|
|
|
@property (nonatomic,strong)UIView *bgView;
|
|
|
|
|
|
@property (nonatomic,strong)UIImageView *topImageView;
|
|
|
|
|
|
@property (nonatomic,strong)UIView *bottomView;
|
|
|
|
|
|
@property (nonatomic,strong)UIScrollView *scrollView;
|
|
|
|
|
|
@property (nonatomic,strong)UILabel *messageLabel;
|
|
|
|
|
|
@property (nonatomic,strong)UIButton *cancelBtn;
|
|
|
|
|
|
@property (nonatomic,strong)UIButton *commitBtn;
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
@implementation QXAppVersionView
|
|
|
|
|
|
|
|
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame
|
|
|
|
|
|
{
|
|
|
|
|
|
self = [super initWithFrame:frame];
|
|
|
|
|
|
if (self) {
|
|
|
|
|
|
self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
|
|
|
|
|
|
[self createViews];
|
|
|
|
|
|
}
|
|
|
|
|
|
return self;
|
|
|
|
|
|
}
|
|
|
|
|
|
-(void)createViews{
|
|
|
|
|
|
self.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.5];
|
|
|
|
|
|
self.bgView = [[UIView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-ScaleWidth(275))/2.0, -self.height, ScaleWidth(275), ScaleWidth(362))];
|
|
|
|
|
|
// self.bgView.backgroundColor = [UIColor whiteColor];
|
|
|
|
|
|
[self.bgView addRoundedCornersWithRadius:16];
|
|
|
|
|
|
[self addSubview:self.bgView];
|
|
|
|
|
|
|
|
|
|
|
|
self.topImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"app_update_top_bg"]];
|
|
|
|
|
|
self.topImageView.frame = CGRectMake(0, 0, self.bgView.width, ScaleWidth(170));
|
2025-10-30 00:45:15 +08:00
|
|
|
|
self.topImageView.contentMode = UIViewContentModeScaleToFill;
|
2025-10-20 09:43:10 +08:00
|
|
|
|
[self.bgView addSubview:self.topImageView];
|
|
|
|
|
|
|
|
|
|
|
|
self.bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, self.topImageView.bottom-ScaleWidth(12), self.bgView.width, self.bgView.height-self.topImageView.height+ScaleWidth(12))];
|
|
|
|
|
|
self.bottomView.backgroundColor = RGB16(0xffffff);
|
|
|
|
|
|
[self.bottomView addRoundedCornersWithRadius:16 byRoundingCorners:(UIRectCornerBottomLeft|UIRectCornerBottomRight)];
|
|
|
|
|
|
[self.bgView addSubview:self.bottomView];
|
|
|
|
|
|
|
|
|
|
|
|
self.commitBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.bgView.width-ScaleWidth(110)-20, self.bottomView.height-42-12, ScaleWidth(110), 42)];
|
|
|
|
|
|
[self.commitBtn addRoundedCornersWithRadius:21];
|
|
|
|
|
|
self.commitBtn.backgroundColor = QXConfig.themeColor;
|
|
|
|
|
|
[self.commitBtn setTitle:QXText(@"立即升级") forState:(UIControlStateNormal)];
|
|
|
|
|
|
[self.commitBtn setTitleColor:QXConfig.btnTextColor forState:(UIControlStateNormal)];
|
|
|
|
|
|
self.commitBtn.titleLabel.font = [UIFont systemFontOfSize:14];
|
|
|
|
|
|
[self.commitBtn addTarget:self action:@selector(commitAction) forControlEvents:(UIControlEventTouchUpInside)];
|
|
|
|
|
|
[self.bottomView addSubview:self.commitBtn];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.cancelBtn = [[UIButton alloc] initWithFrame:CGRectMake(20, self.bottomView.height-42-12, ScaleWidth(110), 42)];
|
|
|
|
|
|
[self.cancelBtn addRoundedCornersWithRadius:21];
|
|
|
|
|
|
self.cancelBtn.backgroundColor = RGB16(0xF3F3F3);
|
|
|
|
|
|
[self.cancelBtn setTitle:QXText(@"取消") forState:(UIControlStateNormal)];
|
|
|
|
|
|
[self.cancelBtn setTitleColor:RGB16(0x999999) forState:(UIControlStateNormal)];
|
|
|
|
|
|
self.cancelBtn.titleLabel.font = [UIFont systemFontOfSize:14];
|
|
|
|
|
|
[self.cancelBtn addTarget:self action:@selector(cancelAction) forControlEvents:(UIControlEventTouchUpInside)];
|
|
|
|
|
|
[self.bottomView addSubview:self.cancelBtn];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(13, 0, self.bgView.width-26, self.commitBtn.top-13)];
|
|
|
|
|
|
[self.bottomView addSubview:self.scrollView];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.messageLabel = [[UILabel alloc] initWithFrame:self.scrollView.bounds];
|
|
|
|
|
|
self.messageLabel.font = [UIFont boldSystemFontOfSize:14];
|
|
|
|
|
|
self.messageLabel.textColor = RGB16(0x000000);
|
|
|
|
|
|
self.messageLabel.textAlignment = NSTextAlignmentCenter;
|
|
|
|
|
|
self.messageLabel.numberOfLines = 0;
|
|
|
|
|
|
[self.scrollView addSubview:self.messageLabel];
|
|
|
|
|
|
}
|
|
|
|
|
|
-(void)setModel:(QXAppVersionModel *)model{
|
|
|
|
|
|
_model = model;
|
|
|
|
|
|
self.messageLabel.text = model.content;
|
|
|
|
|
|
// self.messageLabel.text = @"动环监控撒谎大健康撒谎科技打撒好看到货时间阿克汉登记卡撒大花洒科技活动极客飒户djsakljdk电视剧啊快回家读书卡多撒u一还有第四u啊个ID撒个hi打撒低功耗设计啊开工大吉萨嘎合计打撒好多个健身卡刚回到家撒合计扩大活动时间卡号大健康撒谎登记卡到货时间啊客户端健身卡核打静待花开撒会尽快的撒回到家凯撒会尽快的撒回到家凯撒会尽快的撒大花洒客户端手机卡击凯撒籍卡打撒";
|
|
|
|
|
|
[self.messageLabel sizeToFit];
|
|
|
|
|
|
self.scrollView.contentSize = CGSizeMake(self.bgView.width-26, self.messageLabel.height);
|
|
|
|
|
|
if (model.is_force.intValue == 1) {
|
|
|
|
|
|
self.cancelBtn.hidden = YES;
|
|
|
|
|
|
self.commitBtn.frame = CGRectMake((self.bgView.width-ScaleWidth(110))/2, self.bottomView.height-42-12, ScaleWidth(110), 42);
|
|
|
|
|
|
}else{
|
|
|
|
|
|
self.cancelBtn.hidden = NO;
|
|
|
|
|
|
self.commitBtn.frame = CGRectMake(self.bgView.width-ScaleWidth(110)-20, self.bottomView.height-42-12, ScaleWidth(110), 42);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
-(void)cancelAction{
|
|
|
|
|
|
[self hide];
|
|
|
|
|
|
}
|
|
|
|
|
|
-(void)commitAction{
|
|
|
|
|
|
if ([self.model.url isExist]) {
|
|
|
|
|
|
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:self.model.url] options:@{} completionHandler:nil];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
-(void)showInView:(UIView *)view{
|
|
|
|
|
|
[view addSubview:self];
|
|
|
|
|
|
[UIView animateWithDuration:0.3 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:1.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
|
|
|
|
|
|
self.bgView.y = (SCREEN_HEIGHT-ScaleWidth(362))/2.0;
|
|
|
|
|
|
} completion:^(BOOL finished) {
|
|
|
|
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
-(void)hide{
|
|
|
|
|
|
[UIView animateWithDuration:0.3 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:1.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
|
|
|
|
|
|
self.bgView.y = SCREEN_HEIGHT;
|
|
|
|
|
|
} completion:^(BOOL finished) {
|
|
|
|
|
|
[self removeFromSuperview];
|
|
|
|
|
|
}];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@implementation QXVersionComparator
|
|
|
|
|
|
|
|
|
|
|
|
+ (NSInteger)compareVersion:(NSString *)newVersion withOldVersion:(NSString *)oldVersion {
|
|
|
|
|
|
// 处理空值情况
|
|
|
|
|
|
if (!newVersion || !oldVersion) {
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 去除可能的前缀(如"v")
|
|
|
|
|
|
newVersion = [self removeVersionPrefix:newVersion];
|
|
|
|
|
|
oldVersion = [self removeVersionPrefix:oldVersion];
|
|
|
|
|
|
|
|
|
|
|
|
// 分割版本号
|
|
|
|
|
|
NSArray *newComponents = [newVersion componentsSeparatedByString:@"."];
|
|
|
|
|
|
NSArray *oldComponents = [oldVersion componentsSeparatedByString:@"."];
|
|
|
|
|
|
|
|
|
|
|
|
// 获取最大组件数
|
|
|
|
|
|
NSInteger maxCount = MAX(newComponents.count, oldComponents.count);
|
|
|
|
|
|
|
|
|
|
|
|
for (NSInteger i = 0; i < maxCount; i++) {
|
|
|
|
|
|
// 获取当前位的版本号,如果不存在则默认为0
|
|
|
|
|
|
NSInteger newPart = (i < newComponents.count) ? [newComponents[i] integerValue] : 0;
|
|
|
|
|
|
NSInteger oldPart = (i < oldComponents.count) ? [oldComponents[i] integerValue] : 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (newPart > oldPart) {
|
|
|
|
|
|
return 1; // 新版本更大
|
|
|
|
|
|
} else if (newPart < oldPart) {
|
|
|
|
|
|
return -1; // 旧版本更大
|
|
|
|
|
|
}
|
|
|
|
|
|
// 如果相等,继续比较下一位
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 0; // 版本完全相同
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+ (BOOL)shouldUpdateFromVersion:(NSString *)oldVersion toVersion:(NSString *)newVersion {
|
|
|
|
|
|
NSInteger result = [self compareVersion:newVersion withOldVersion:oldVersion];
|
|
|
|
|
|
return result == 1; // 只有新版本更大时才需要更新
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 移除版本号前缀(如"v1.0.0" -> "1.0.0")
|
|
|
|
|
|
+ (NSString *)removeVersionPrefix:(NSString *)version {
|
|
|
|
|
|
if (!version) return @"";
|
|
|
|
|
|
|
|
|
|
|
|
// 去除空格
|
|
|
|
|
|
version = [version stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
|
|
|
|
|
|
|
|
|
|
|
|
// 如果以"v"或"V"开头,去除前缀
|
|
|
|
|
|
if (version.length > 0 && [[version substringToIndex:1] caseInsensitiveCompare:@"v"] == NSOrderedSame) {
|
|
|
|
|
|
version = [version substringFromIndex:1];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return version;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@end
|