Commit 566e72bd cgx

优化H5

1 个父辈 d9481f95
...@@ -9,9 +9,16 @@ ...@@ -9,9 +9,16 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@protocol DsWebControllerDelegate <NSObject>
/// 刷新AI睡眠教练页面
- (void)reloadAIPage;
@end
/// 加载H5页面控制器 /// 加载H5页面控制器
@interface DsWebController : UIViewController @interface DsWebController : UIViewController
@property (nonatomic, weak) id<DsWebControllerDelegate> refreshDelegate;
/// 初始化方法 /// 初始化方法
/// @param title 导航栏标题 /// @param title 导航栏标题
/// @param link 传入h5链接 /// @param link 传入h5链接
......
...@@ -110,7 +110,12 @@ ...@@ -110,7 +110,12 @@
NSDictionary *bodyDic = message.body; NSDictionary *bodyDic = message.body;
int type = [bodyDic[@"type"] intValue]; int type = [bodyDic[@"type"] intValue];
DSLog(@"bodyDic:%@", bodyDic); DSLog(@"bodyDic:%@", bodyDic);
if (type == 88) { [self.navigationController popViewControllerAnimated:YES]; } if (type == 88) {
if (self.refreshDelegate && [self.refreshDelegate respondsToSelector:@selector(reloadAIPage)]) {
[self.refreshDelegate reloadAIPage];
}
[self.navigationController popViewControllerAnimated:YES];
}
} }
} }
......
...@@ -39,6 +39,8 @@ FOUNDATION_EXTERN NSString * const NoiseTimingDidClick; ...@@ -39,6 +39,8 @@ FOUNDATION_EXTERN NSString * const NoiseTimingDidClick;
FOUNDATION_EXTERN NSString * const ExitCoaxSleep; FOUNDATION_EXTERN NSString * const ExitCoaxSleep;
// 刷新AI睡眠教练通知 // 刷新AI睡眠教练通知
FOUNDATION_EXTERN NSString * const NeedUpdateAICoach; FOUNDATION_EXTERN NSString * const NeedUpdateAICoach;
// 更新是否开启AI通知
FOUNDATION_EXTERN NSString * const NeedUpdateStartAI;
// 用户基础信息 // 用户基础信息
FOUNDATION_EXTERN NSString * const UserBasicInfo; FOUNDATION_EXTERN NSString * const UserBasicInfo;
......
...@@ -26,6 +26,7 @@ NSString * const NoisePlaylistHasChange = @"NoisePlaylistHasChangeNoti"; ...@@ -26,6 +26,7 @@ NSString * const NoisePlaylistHasChange = @"NoisePlaylistHasChangeNoti";
NSString * const NoiseTimingDidClick = @"NoiseTimingDidClickNoti"; NSString * const NoiseTimingDidClick = @"NoiseTimingDidClickNoti";
NSString * const ExitCoaxSleep = @"ExitCoaxSleepNoti"; NSString * const ExitCoaxSleep = @"ExitCoaxSleepNoti";
NSString * const NeedUpdateAICoach = @"NeedUpdateAICoachNoti"; NSString * const NeedUpdateAICoach = @"NeedUpdateAICoachNoti";
NSString * const NeedUpdateStartAI = @"NeedUpdateStartAINoti";
NSString * const UserBasicInfo = @"UserBasicInfo"; NSString * const UserBasicInfo = @"UserBasicInfo";
......
...@@ -11,8 +11,9 @@ ...@@ -11,8 +11,9 @@
#import "RelaxTrainController.h" #import "RelaxTrainController.h"
#import "SomeProxy.h" #import "SomeProxy.h"
#import "ThreeMinuteController.h" #import "ThreeMinuteController.h"
#import "UserRequestModel.h"
@interface AISleepCoachController () <WKNavigationDelegate, WKScriptMessageHandler> @interface AISleepCoachController () <WKNavigationDelegate, WKScriptMessageHandler, DsWebControllerDelegate>
@property (strong, nonatomic) WKWebView *aiWebView; @property (strong, nonatomic) WKWebView *aiWebView;
@property (strong, nonatomic) NSMutableURLRequest *request; @property (strong, nonatomic) NSMutableURLRequest *request;
@property (strong, nonatomic) UIProgressView *progressView; @property (strong, nonatomic) UIProgressView *progressView;
...@@ -62,8 +63,6 @@ ...@@ -62,8 +63,6 @@
} else { } else {
[self.aiWebView removeMask]; [self.aiWebView removeMask];
} }
[self.aiWebView reload];
} }
#pragma mark - 登录成功后刷新 #pragma mark - 登录成功后刷新
...@@ -88,9 +87,9 @@ ...@@ -88,9 +87,9 @@
} }
} }
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { #pragma mark - DsWebControllerDelegate
RelaxTrainController *relaxVC = [RelaxTrainController new]; - (void)reloadAIPage {
[self.navigationController pushViewController:relaxVC animated:YES]; [self.aiWebView reload];
} }
#pragma mark - WKWebView的监听方法 #pragma mark - WKWebView的监听方法
...@@ -112,7 +111,9 @@ ...@@ -112,7 +111,9 @@
decisionHandler(WKNavigationActionPolicyAllow); decisionHandler(WKNavigationActionPolicyAllow);
} else { } else {
// 开启新的webview页面加载 // 开启新的webview页面加载
[self.navigationController pushViewController:[[DsWebController alloc] initWithLink:url isShowNavi:NO] animated:YES]; DsWebController *newWebVC = [[DsWebController alloc] initWithLink:url isShowNavi:NO];
newWebVC.refreshDelegate = self;
[self.navigationController pushViewController:newWebVC animated:YES];
decisionHandler(WKNavigationActionPolicyCancel); decisionHandler(WKNavigationActionPolicyCancel);
} }
} }
...@@ -150,7 +151,11 @@ ...@@ -150,7 +151,11 @@
break; break;
case 2: // 登录点击开启-开启我的页面里面的AI睡眠教练 case 2: // 登录点击开启-开启我的页面里面的AI睡眠教练
{ {
[UserRequestModel autoLoginRequestWithCompletion:^(UserRequestModel * _Nonnull requestModel) {
if (requestModel.resCode == DSResCodeSuccess) {
[[NSNotificationCenter defaultCenter] postNotificationName:NeedUpdateStartAI object:nil];
}
}];
} }
break; break;
case 3: // 轻拍哄睡 case 3: // 轻拍哄睡
...@@ -163,6 +168,12 @@ ...@@ -163,6 +168,12 @@
[DSProgressHUD showToast:@"该功能未来会被替换"]; [DSProgressHUD showToast:@"该功能未来会被替换"];
} }
break; break;
case 5: // 练习腹式呼吸法
{
RelaxTrainController *relaxVC = [RelaxTrainController new];
[self.navigationController pushViewController:relaxVC animated:YES];
}
break;
default: default:
break; break;
} }
......
...@@ -218,7 +218,7 @@ ...@@ -218,7 +218,7 @@
} }
} else { } else {
// 跳转到H5页面 // 跳转到H5页面
[weakSelf.navigationController pushViewController:[[DsWebController alloc] initWithTitle:pModel.title link:pModel.page_url] animated:YES]; [weakSelf.navigationController pushViewController:[[DsWebController alloc] initWithLink:pModel.page_url isShowNavi:NO] animated:YES];
} }
} }
......
...@@ -29,6 +29,12 @@ ...@@ -29,6 +29,12 @@
} }
} }
- (void)monitorAIStartNoti {
UserModel *usrModel = [LoginUtils getUserLoginData];
self.openAIBtn.hidden = usrModel.is_access == 1;
self.reportReviewsView.hidden = !self.openAIBtn.hidden;
}
- (void)updateUserView { - (void)updateUserView {
UserModel *model = [LoginUtils getUserLoginData]; UserModel *model = [LoginUtils getUserLoginData];
if (model) { if (model) {
...@@ -47,9 +53,8 @@ ...@@ -47,9 +53,8 @@
make.top.equalTo(self.titleLab.mas_bottom).offset(4); make.top.equalTo(self.titleLab.mas_bottom).offset(4);
make.size.mas_equalTo(CGSizeMake(95, 35)); make.size.mas_equalTo(CGSizeMake(95, 35));
}]; }];
#warning 监听用户是否点击了开启 self.openAIBtn.hidden = model.is_access == 1;
self.openAIBtn.hidden = YES; self.reportReviewsView.hidden = !self.openAIBtn.hidden;
self.reportReviewsView.hidden = NO;
self.scoreCountLab.text = [NSString stringWithFormat:@"我的积分:%d", model.total_points]; self.scoreCountLab.text = [NSString stringWithFormat:@"我的积分:%d", model.total_points];
} else { } else {
self.portraitIV.image = [UIImage imageNamed:@"portrait"]; self.portraitIV.image = [UIImage imageNamed:@"portrait"];
...@@ -183,12 +188,15 @@ ...@@ -183,12 +188,15 @@
// 监听用户数据更新通知 // 监听用户数据更新通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateUserView) name:HasUpdateUserDataNoti object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateUserView) name:HasUpdateUserDataNoti object:nil];
// 监听用户开启AI睡眠教练
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(monitorAIStartNoti) name:NeedUpdateStartAI object:nil];
} }
return self; return self;
} }
- (void)dealloc { - (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self name:HasUpdateUserDataNoti object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:HasUpdateUserDataNoti object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:NeedUpdateStartAI object:nil];
} }
#pragma mark - lazy #pragma mark - lazy
......
...@@ -34,7 +34,8 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -34,7 +34,8 @@ NS_ASSUME_NONNULL_BEGIN
/// 更新sid和token /// 更新sid和token
/// @param sid sid /// @param sid sid
/// @param token token /// @param token token
+ (void)updateSid:(NSString *)sid token:(NSString *)token; /// @param isAccess is_access
+ (void)updateSid:(NSString *)sid token:(NSString *)token isAccess:(int)isAccess;
/// 更新用户头像 /// 更新用户头像
/// @param face_img face_img /// @param face_img face_img
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
+ (NSString *)getToken { + (NSString *)getToken {
UserModel *userModel = [self getUserLoginData]; UserModel *userModel = [self getUserLoginData];
DSLog(@"token:%@", userModel.token);
return userModel.token; return userModel.token;
} }
...@@ -41,10 +42,11 @@ ...@@ -41,10 +42,11 @@
return userModel.birthday; return userModel.birthday;
} }
+ (void)updateSid:(NSString *)sid token:(NSString *)token { + (void)updateSid:(NSString *)sid token:(NSString *)token isAccess:(int)isAccess {
UserModel *userModel = [self getUserLoginData]; UserModel *userModel = [self getUserLoginData];
userModel.sid = sid; userModel.sid = sid;
userModel.token = token; userModel.token = token;
userModel.is_access = isAccess;
[self saveUserLoginData:userModel]; [self saveUserLoginData:userModel];
} }
...@@ -80,6 +82,7 @@ ...@@ -80,6 +82,7 @@
+ (void)clearUserLoginData { + (void)clearUserLoginData {
kUserDefaultsRemoveObj(UserBasicInfo); kUserDefaultsRemoveObj(UserBasicInfo);
kUserDefaultsSynchronize;
// 发送更新用户数据显示UI通知 // 发送更新用户数据显示UI通知
[[NSNotificationCenter defaultCenter] postNotificationName:HasUpdateUserDataNoti object:nil]; [[NSNotificationCenter defaultCenter] postNotificationName:HasUpdateUserDataNoti object:nil];
......
...@@ -28,6 +28,7 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -28,6 +28,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, copy) NSString *user_name; @property (nonatomic, copy) NSString *user_name;
// 用户头像 // 用户头像
@property (nonatomic, copy) NSString *face_img; @property (nonatomic, copy) NSString *face_img;
// 是否开启AI
@property (nonatomic, assign) int is_access; @property (nonatomic, assign) int is_access;
#pragma mark - 用户等级积分 #pragma mark - 用户等级积分
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
[aCoder encodeObject:_token forKey:@"token"]; [aCoder encodeObject:_token forKey:@"token"];
[aCoder encodeObject:_sid forKey:@"sid"]; [aCoder encodeObject:_sid forKey:@"sid"];
[aCoder encodeObject:_face_img forKey:@"face_img"]; [aCoder encodeObject:_face_img forKey:@"face_img"];
[aCoder encodeObject:@(_is_access) forKey:@"is_access"];
[aCoder encodeObject:_level_img forKey:@"level_img"]; [aCoder encodeObject:_level_img forKey:@"level_img"];
[aCoder encodeObject:@(_total_points) forKey:@"total_points"]; [aCoder encodeObject:@(_total_points) forKey:@"total_points"];
} }
...@@ -29,6 +30,7 @@ ...@@ -29,6 +30,7 @@
_token = [aDecoder decodeObjectForKey:@"token"]; _token = [aDecoder decodeObjectForKey:@"token"];
_sid = [aDecoder decodeObjectForKey:@"sid"]; _sid = [aDecoder decodeObjectForKey:@"sid"];
_face_img = [aDecoder decodeObjectForKey:@"face_img"]; _face_img = [aDecoder decodeObjectForKey:@"face_img"];
_is_access = [[aDecoder decodeObjectForKey:@"is_access"] intValue];
_level_img = [aDecoder decodeObjectForKey:@"level_img"]; _level_img = [aDecoder decodeObjectForKey:@"level_img"];
_total_points = [[aDecoder decodeObjectForKey:@"total_points"] intValue]; _total_points = [[aDecoder decodeObjectForKey:@"total_points"] intValue];
return self; return self;
......
...@@ -103,7 +103,7 @@ ...@@ -103,7 +103,7 @@
return [self httpPostBodyRequestWithAPI:api params:@{@"query" : argStr} view:nil hasNetActivity:YES loadingInfo:nil hasFailInfo:YES success:^(NSDictionary * _Nonnull apiDic) { return [self httpPostBodyRequestWithAPI:api params:@{@"query" : argStr} view:nil hasNetActivity:YES loadingInfo:nil hasFailInfo:YES success:^(NSDictionary * _Nonnull apiDic) {
DSLog(@"用户自动登录接口apiDic:%@\n, token:%@\n, sid:%@", apiDic, token, [LoginUtils getSid]); DSLog(@"用户自动登录接口apiDic:%@\n, token:%@\n, sid:%@", apiDic, token, [LoginUtils getSid]);
NSDictionary *resultDic = apiDic[@"result"]; NSDictionary *resultDic = apiDic[@"result"];
[LoginUtils updateSid:resultDic[@"sid"] token:resultDic[@"token"]]; [LoginUtils updateSid:resultDic[@"sid"] token:resultDic[@"token"] isAccess:[resultDic[@"is_access"] intValue]];
DSLog(@"自动登录成功后token:%@\n, sid:%@", [LoginUtils getToken], [LoginUtils getSid]); DSLog(@"自动登录成功后token:%@\n, sid:%@", [LoginUtils getToken], [LoginUtils getSid]);
requestModel.resCode = DSResCodeSuccess; requestModel.resCode = DSResCodeSuccess;
completion(requestModel); completion(requestModel);
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!