This commit is contained in:
启星
2025-09-29 17:21:49 +08:00
parent 9307d88177
commit 2a44a06630
138 changed files with 2802 additions and 439 deletions

View File

@@ -31,12 +31,15 @@
#import "QXMeetActivityDriftView.h" //
#import "QXChirldModeViewController.h"
#import "QXAppVersionView.h"
#import "QXLoginNetwork.h"
@interface QXTabbarController ()<UITabBarControllerDelegate,QXTabBarDelegate,UINavigationControllerDelegate,MQTTClientModelDelegate,V2TIMConversationListener>
@property(nonatomic,strong) QXTabBar *customTabBar;
@property(nonatomic,strong) QXHomeViewController *homeVC;
@property(nonatomic,strong) QXMeetActivityDriftView *meetView;
@property(nonatomic,assign) BOOL isAlreadyShowChirld;
@property(nonatomic,strong) QXAppVersionView *appUpdateView;
@end
@implementation QXTabbarController
@@ -60,6 +63,32 @@
[self popChirldView];
}
QXLOG(@"视图即将展示");
[self getAppVersion];
}
-(void)getAppVersion{
MJWeakSelf
[QXLoginNetwork getAppVersionSuccessBlock:^(QXAppVersionModel * _Nonnull model) {
NSString *currentVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
NSString *latestVersion = model.version; //
NSInteger result = [QXVersionComparator compareVersion:latestVersion withOldVersion:currentVersion];
switch (result) {
case 1:
NSLog(@"需要更新:新版本 %@ 比当前版本 %@ 新", latestVersion, currentVersion);
weakSelf.appUpdateView.model = model;
[weakSelf.appUpdateView showInView:KEYWINDOW];
break;
case 0:
NSLog(@"版本相同:当前版本 %@ 已是最新", currentVersion);
break;
case -1:
NSLog(@"版本异常:新版本 %@ 比当前版本 %@ 旧", latestVersion, currentVersion);
break;
}
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
}];
}
#pragma mark -
-(void)popChirldView{
@@ -288,6 +317,12 @@
}
-(QXAppVersionView *)appUpdateView{
if (!_appUpdateView) {
_appUpdateView = [[QXAppVersionView alloc] init];
}
return _appUpdateView;
}
//-(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
// NSInteger index = [self.viewControllers indexOfObject:viewController];

View File

@@ -0,0 +1,40 @@
//
// QXAppVersionView.h
// QXLive
//
// Created by 启星 on 2025/9/27.
//
#import <UIKit/UIKit.h>
#import "QXAppVersionModel.h"
NS_ASSUME_NONNULL_BEGIN
@interface QXAppVersionView : UIView
@property (nonatomic,strong)QXAppVersionModel *model;
-(void)showInView:(UIView *)view;
-(void)hide;
@end
@interface QXVersionComparator : NSObject
/**
比较两个版本号是否需要更新
@param newVersion 新版本号(服务器返回的版本)
@param oldVersion 旧版本号(当前应用版本)
@return 比较结果:-1=旧版本更大0=版本相同1=新版本更大(需要更新)
*/
+ (NSInteger)compareVersion:(NSString *)newVersion withOldVersion:(NSString *)oldVersion;
/**
检查是否需要更新
@param newVersion 新版本号
@param oldVersion 旧版本号
@return YES=需要更新NO=不需要更新
*/
+ (BOOL)shouldUpdateFromVersion:(NSString *)oldVersion toVersion:(NSString *)newVersion;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,200 @@
//
// 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)UILabel *titleLabel;
@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(400))];
self.bgView.backgroundColor = [UIColor whiteColor];
[self.bgView addRoundedCornersWithRadius:16];
[self addSubview:self.bgView];
self.titleLabel = [[UILabel alloc] init];
self.titleLabel.font = [UIFont boldSystemFontOfSize:16];
self.titleLabel.text = QXText(@"发现新版本");
self.titleLabel.textColor = RGB16(0x333333);
[self.bgView addSubview:self.titleLabel];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.bgView);
make.top.equalTo(self.bgView).offset(16);
make.height.mas_equalTo(24);
}];
self.commitBtn = [[UIButton alloc] init];
[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.bgView addSubview:self.commitBtn];
[self.commitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.bgView).offset(-12);
make.height.mas_equalTo(42);
make.width.mas_equalTo(ScaleWidth(110));
make.right.mas_equalTo(-20);
}];
self.cancelBtn = [[UIButton alloc] init];
[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.bgView addSubview:self.cancelBtn];
[self.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.bgView).offset(-12);
make.height.mas_equalTo(42);
make.width.mas_equalTo(ScaleWidth(110));
make.left.mas_equalTo(20);
}];
self.messageLabel = [[UILabel alloc] init];
self.messageLabel.font = [UIFont boldSystemFontOfSize:16];
self.messageLabel.textColor = RGB16(0x000000);
self.messageLabel.textAlignment = NSTextAlignmentCenter;
self.messageLabel.numberOfLines = 0;
[self.bgView addSubview:self.messageLabel];
[self.messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.titleLabel.mas_bottom).offset(10);
make.left.equalTo(self.bgView).offset(16);
make.right.equalTo(self.bgView).offset(-16);
make.bottom.equalTo(self.commitBtn.mas_top).offset(-10);
}];
}
-(void)setModel:(QXAppVersionModel *)model{
_model = model;
self.messageLabel.text = model.content;
if (model.is_force.intValue == 1) {
self.cancelBtn.hidden = YES;
[self.commitBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.bgView).offset(-12);
make.height.mas_equalTo(42);
make.width.mas_equalTo(ScaleWidth(110));
make.centerX.equalTo(self.bgView);
}];
}else{
self.cancelBtn.hidden = NO;
[self.commitBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.bgView).offset(-12);
make.height.mas_equalTo(42);
make.width.mas_equalTo(ScaleWidth(110));
make.right.mas_equalTo(-20);
}];
}
}
-(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(300))/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