Commit 000404e3 cgx

优化APP版本更新

1 个父辈 0563bb90
#include "Pods/Target Support Files/Pods-DreamSleep/Pods-DreamSleep.beta.xcconfig" #include "Pods/Target Support Files/Pods-DreamSleep/Pods-DreamSleep.beta.xcconfig"
// 测试环境 /// 测试环境配置文件
// 主机地址 /// 主机地址
SLANT = / SLANT = /
HOST_URL = https:${SLANT}/cbti.mynatapp.cc HOST_URL = https:${SLANT}/cbti.mynatapp.cc
......
// 自定义xcconfg文件,如果使用了cocoapods,需要引入pod中的xcconfig,解决了pod install⚠️ // 自定义xcconfg文件,如果使用了cocoapods,需要引入pod中的xcconfig,解决了pod install⚠️
#include "Pods/Target Support Files/Pods-DreamSleep/Pods-DreamSleep.debug.xcconfig" #include "Pods/Target Support Files/Pods-DreamSleep/Pods-DreamSleep.debug.xcconfig"
// 开发环境 /// 开发环境配置文件
// 主机地址 /// 主机地址
SLANT = / SLANT = /
HOST_URL = https:${SLANT}/cbti.mynatapp.cc HOST_URL = https:${SLANT}/cbti.mynatapp.cc
#include "Pods/Target Support Files/Pods-DreamSleep/Pods-DreamSleep.release.xcconfig" #include "Pods/Target Support Files/Pods-DreamSleep/Pods-DreamSleep.release.xcconfig"
// 正式环境 /// 正式环境配置文件
// 主机地址 /// 主机地址
SLANT = / SLANT = /
HOST_URL = https:${SLANT}/www.cbti.cn HOST_URL = https:${SLANT}/www.cbti.cn
// 给正式环境配置Preprocessor Macros,用于开启友盟数据埋点统计 /// 给正式环境配置Preprocessor Macros
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) OPEN_DATA_STATISTICS=1 /// 用于开启友盟数据埋点统计、APP更新
/// DSRELEASE前面必须有空格
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) DSRELEASE=1
...@@ -26,8 +26,8 @@ NSString * const RelaxTrain = @"RelaxTrain"; ...@@ -26,8 +26,8 @@ NSString * const RelaxTrain = @"RelaxTrain";
+ (void)event:(NSString *)eventId attributes:(NSDictionary *)attributes { + (void)event:(NSString *)eventId attributes:(NSDictionary *)attributes {
// 只统计正式环境的数据 // 只统计正式环境的数据
#if OPEN_DATA_STATISTICS == 1 #if DSRELEASE == 1
// NSLog(@"eventId:%@, attributes:%@", eventId, attributes); DSLog(@"eventId:%@, attributes:%@", eventId, attributes);
[MobClick event:eventId attributes:attributes]; [MobClick event:eventId attributes:attributes];
#endif #endif
} }
......
...@@ -68,6 +68,9 @@ FOUNDATION_EXTERN NSString * const UMengAppKey; ...@@ -68,6 +68,9 @@ FOUNDATION_EXTERN NSString * const UMengAppKey;
/** AppSotreID */ /** AppSotreID */
FOUNDATION_EXTERN NSString * const AppSotreID; FOUNDATION_EXTERN NSString * const AppSotreID;
/// APP选择更新弹框时间控制
FOUNDATION_EXTERN NSString * const SelectUpdateTime;
/// 常用常量值 /// 常用常量值
@interface DSConstUtil : NSObject @interface DSConstUtil : NSObject
@end @end
......
...@@ -46,5 +46,7 @@ NSString * const UMengAppKey = @"62048053e0f9bb492bfcb0e8"; ...@@ -46,5 +46,7 @@ NSString * const UMengAppKey = @"62048053e0f9bb492bfcb0e8";
NSString * const AppSotreID = @"1609336070"; NSString * const AppSotreID = @"1609336070";
NSString * const SelectUpdateTime = @"SelectUpdateTime";
@implementation DSConstUtil @implementation DSConstUtil
@end @end
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#import "NoisePlayBar.h" #import "NoisePlayBar.h"
#import "NoisePlayerManager.h" #import "NoisePlayerManager.h"
#import "DailyTaskController.h" #import "DailyTaskController.h"
#import "VersionUpdateBox.h"
@interface HomeViewController () @interface HomeViewController ()
@property (nonatomic, strong) DSHomeView *homeTV; @property (nonatomic, strong) DSHomeView *homeTV;
...@@ -30,6 +31,9 @@ ...@@ -30,6 +31,9 @@
@property (nonatomic, strong) NSArray *helpListData; @property (nonatomic, strong) NSArray *helpListData;
/// 所有白噪音类型数据 /// 所有白噪音类型数据
@property (nonatomic, strong) NSArray *noiseTypeArr; @property (nonatomic, strong) NSArray *noiseTypeArr;
/// APP更新弹框
@property (nonatomic, strong) VersionUpdateBox *updateBox;
@property (nonatomic, assign) int update_Way;
@end @end
@implementation HomeViewController @implementation HomeViewController
...@@ -72,6 +76,15 @@ ...@@ -72,6 +76,15 @@
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needUpdate) name:NeedUpdateHomePage object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needUpdate) name:NeedUpdateHomePage object:nil];
// 监听需要暂停所有白噪音 // 监听需要暂停所有白噪音
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pauseAllNoise) name:NeedPauseAllNoise object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pauseAllNoise) name:NeedPauseAllNoise object:nil];
#if DSRELEASE == 1
// 设置初始值
self.update_Way = -1;
[self appWillEnterForeground];
// 监听APP回到前台通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillEnterForeground) name:UIApplicationWillEnterForegroundNotification object:nil];
#endif
} }
- (void)viewWillAppear:(BOOL)animated { - (void)viewWillAppear:(BOOL)animated {
...@@ -104,6 +117,10 @@ ...@@ -104,6 +117,10 @@
- (void)dealloc { - (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self name:NeedUpdateHomePage object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:NeedUpdateHomePage object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:NeedPauseAllNoise object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:NeedPauseAllNoise object:nil];
#if DSRELEASE == 1
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillEnterForegroundNotification object:nil];
#endif
} }
#pragma mark - 先放大,再缩小 #pragma mark - 先放大,再缩小
...@@ -302,6 +319,7 @@ ...@@ -302,6 +319,7 @@
} }
} }
#pragma mark - 每日任务相关
- (void)jumpToDailyTaskPage { - (void)jumpToDailyTaskPage {
if ([LoginUtils getUserLoginData]) { if ([LoginUtils getUserLoginData]) {
[self.navigationController pushViewController:[DailyTaskController new] animated:YES]; [self.navigationController pushViewController:[DailyTaskController new] animated:YES];
...@@ -310,6 +328,60 @@ ...@@ -310,6 +328,60 @@
} }
} }
#pragma mark - APP升级相关
- (void)appWillEnterForeground {
// 已经是最新版本
if (self.update_Way == 2) { return; }
if (self.update_Way == -1) {
// 第一次进入
[self updateVersionAction];
} else if (self.update_Way == 0) {
// 如果是强制更新(APP每次回到前台调用)
[self updateVersionAction];
} else if (self.update_Way == 1) {
if ([self isNeedShowUpdateBox]) {
[self updateVersionAction];
} else {
DSLog(@"一天只能提示用户选择更新1次");
}
}
}
- (void)updateVersionAction {
[VersionRequestModel queryAppVersionRequestWithCompletion:^(VersionRequestModel * _Nonnull requestModel) {
if (requestModel.resCode == DSResCodeSuccess) {
self.update_Way = requestModel.update_Way;
// 本地版本 < 服务器版本
if ([DSAppVersion compare:requestModel.version_Num options:NSNumericSearch] == NSOrderedAscending) {
// 服务器返回的是选择更新并且1天内未弹框
if (self.update_Way == 1 && [self isNeedShowUpdateBox]) {
[self.updateBox showWithVersionNum:requestModel.version_Num content:requestModel.version_Content isForce:NO];
return;
}
// 强制更新
if (self.update_Way == 0) {
[self.updateBox showWithVersionNum:requestModel.version_Num content:requestModel.version_Content isForce:YES];
}
} else {
// 本地版本 >= 服务器版本
self.update_Way = 2;
}
}
}];
}
- (BOOL)isNeedShowUpdateBox {
// 用户选择更新(每隔1天触发1次)
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd"];
NSString *ageDateString = [dateFormatter stringFromDate:kGetUserDefaultsObj(SelectUpdateTime)];
NSString *nowDateString = [dateFormatter stringFromDate:[NSDate date]];
DSLog(@"日期比较之前:%@ 现在:%@", ageDateString, nowDateString);
return ![ageDateString isEqualToString:nowDateString];
}
#pragma mark - 导航栏日间、黑夜模式 #pragma mark - 导航栏日间、黑夜模式
- (NaviStyle)navigationBarStyle { - (NaviStyle)navigationBarStyle {
return [self.dk_manager.themeVersion isEqualToString:DKThemeVersionNormal] ? NaviStyleLight : NaviStyleDark; return [self.dk_manager.themeVersion isEqualToString:DKThemeVersionNormal] ? NaviStyleLight : NaviStyleDark;
...@@ -330,4 +402,11 @@ ...@@ -330,4 +402,11 @@
return _noisePlayBar; return _noisePlayBar;
} }
- (VersionUpdateBox *)updateBox {
if (!_updateBox) {
_updateBox = [[VersionUpdateBox alloc] initWithFrame:CGRectZero];
}
return _updateBox;
}
@end @end
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
// //
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "VersionRequestModel.h"
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
......
...@@ -58,6 +58,10 @@ ...@@ -58,6 +58,10 @@
#pragma mark - Action #pragma mark - Action
- (void)closeAction { - (void)closeAction {
// 用户手动点击关闭更新按钮才记录弹窗时间
kSetUserDefaultsObj([NSDate date], SelectUpdateTime);
kUserDefaultsSynchronize;
[self dismiss]; [self dismiss];
} }
......
...@@ -84,7 +84,7 @@ ...@@ -84,7 +84,7 @@
#if DEBUG == 1 // Dev和Beta环境下打开log信息 #if DEBUG == 1 // Dev和Beta环境下打开log信息
[UMConfigure setLogEnabled:YES]; [UMConfigure setLogEnabled:YES];
#else #elif DSRELEASE == 1
[UMConfigure setLogEnabled:NO]; [UMConfigure setLogEnabled:NO];
#endif #endif
...@@ -107,10 +107,12 @@ ...@@ -107,10 +107,12 @@
// } // }
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options { - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options {
#warning 实时监控,用于集成测试,上线后去掉 // 实时监控,用于集成测试,上线后去掉
// if ([MobClick handleUrl:url]) { #if DEBUG == 1
// return YES; if ([MobClick handleUrl:url]) {
// } return YES;
}
#endif
// 处理微信登录 // 处理微信登录
if ([url.absoluteString containsString:@"login"]) { if ([url.absoluteString containsString:@"login"]) {
......
...@@ -6,13 +6,10 @@ ...@@ -6,13 +6,10 @@
// //
#import "DSTabBarController.h" #import "DSTabBarController.h"
#import "VersionUpdateBox.h"
#import "VersionRequestModel.h"
@interface DSTabBarController () @interface DSTabBarController ()
// 记录上一次点击tabbar // 记录上一次点击tabbar
@property (nonatomic, assign) NSInteger indexFlag; @property (nonatomic, assign) NSInteger indexFlag;
@property (nonatomic, strong) VersionUpdateBox *updateBox;
@end @end
@implementation DSTabBarController @implementation DSTabBarController
...@@ -20,40 +17,6 @@ ...@@ -20,40 +17,6 @@
- (void)viewDidLoad { - (void)viewDidLoad {
[super viewDidLoad]; [super viewDidLoad];
// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateVersionAction) name:UIApplicationDidBecomeActiveNotification object:nil];
}
- (void)updateVersionAction {
// [VersionRequestModel queryAppVersionRequestWithCompletion:^(VersionRequestModel * _Nonnull requestModel) {
//
// }];
NSString *url = [NSString stringWithFormat:@"https://itunes.apple.com/cn/lookup?id=%@", AppSotreID];
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/javascript", nil];
[manager POST:url parameters:nil headers:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSArray *results = responseObject[@"results"];
if (results.count > 0) {
// 获取版本号
NSString *serverVersion = responseObject[@"results"][0][@"version"];
// 获取当前版本号
NSString *appVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
DSLog(@"serverVersion:%@, appVersion:%@", serverVersion, appVersion);
// 判断本地版本与App Store版本是否一致
if ([appVersion compare:serverVersion options:NSNumericSearch] == NSOrderedAscending) {
[self.updateBox showVersionUpdate:NO];
} else {
[DSProgressHUD showToast:@"当前已是最新版本"];
}
} else {
[DSProgressHUD showToast:@"请去App Store查看是否有更新"];
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[DSProgressHUD showToast:@"获取App Store最新版本失败"];
DSLog(@"error:%@", error);
}];
} }
- (void)viewWillAppear:(BOOL)animated { - (void)viewWillAppear:(BOOL)animated {
...@@ -75,10 +38,6 @@ ...@@ -75,10 +38,6 @@
} }
} }
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];
}
#pragma mark - UITabBarDelegate #pragma mark - UITabBarDelegate
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item { - (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
NSInteger index = [self.tabBar.items indexOfObject:item]; NSInteger index = [self.tabBar.items indexOfObject:item];
...@@ -116,12 +75,4 @@ ...@@ -116,12 +75,4 @@
[[btns[index] layer] addAnimation:animation forKey:nil]; [[btns[index] layer] addAnimation:animation forKey:nil];
} }
#pragma mark - lazy
- (VersionUpdateBox *)updateBox {
if (!_updateBox) {
_updateBox = [[VersionUpdateBox alloc] initWithFrame:CGRectZero];
}
return _updateBox;
}
@end @end
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!