Commit d9481f95 cgx

对接AI睡眠教练H5页面

1 个父辈 79c635e9
...@@ -179,6 +179,9 @@ ...@@ -179,6 +179,9 @@
D0D4107F2844D38400009638 /* RankModel.m in Sources */ = {isa = PBXBuildFile; fileRef = D0D4107E2844D38400009638 /* RankModel.m */; }; D0D4107F2844D38400009638 /* RankModel.m in Sources */ = {isa = PBXBuildFile; fileRef = D0D4107E2844D38400009638 /* RankModel.m */; };
D0D69ED3282360F100A0D5EB /* LookAllController.m in Sources */ = {isa = PBXBuildFile; fileRef = D0D69ED2282360F100A0D5EB /* LookAllController.m */; }; D0D69ED3282360F100A0D5EB /* LookAllController.m in Sources */ = {isa = PBXBuildFile; fileRef = D0D69ED2282360F100A0D5EB /* LookAllController.m */; };
D0D69ED628236E0800A0D5EB /* SafeSleepListController.m in Sources */ = {isa = PBXBuildFile; fileRef = D0D69ED528236E0800A0D5EB /* SafeSleepListController.m */; }; D0D69ED628236E0800A0D5EB /* SafeSleepListController.m in Sources */ = {isa = PBXBuildFile; fileRef = D0D69ED528236E0800A0D5EB /* SafeSleepListController.m */; };
D0D96FDF2848457900461839 /* RelaxTrainRequestModel.m in Sources */ = {isa = PBXBuildFile; fileRef = D0D96FDE2848457900461839 /* RelaxTrainRequestModel.m */; };
D0D96FE22848493700461839 /* RelaxTrainModel.m in Sources */ = {isa = PBXBuildFile; fileRef = D0D96FE12848493700461839 /* RelaxTrainModel.m */; };
D0D96FE52848698F00461839 /* SomeProxy.m in Sources */ = {isa = PBXBuildFile; fileRef = D0D96FE32848698E00461839 /* SomeProxy.m */; };
D0DB33A528204E7C00E15914 /* FirstLeadAlertView.m in Sources */ = {isa = PBXBuildFile; fileRef = D0DB33A428204E7C00E15914 /* FirstLeadAlertView.m */; }; D0DB33A528204E7C00E15914 /* FirstLeadAlertView.m in Sources */ = {isa = PBXBuildFile; fileRef = D0DB33A428204E7C00E15914 /* FirstLeadAlertView.m */; };
D0DB33A828224D5100E15914 /* PromotionModel.m in Sources */ = {isa = PBXBuildFile; fileRef = D0DB33A728224D5100E15914 /* PromotionModel.m */; }; D0DB33A828224D5100E15914 /* PromotionModel.m in Sources */ = {isa = PBXBuildFile; fileRef = D0DB33A728224D5100E15914 /* PromotionModel.m */; };
D0DF90AE2814390000FC0F64 /* BannerModel.m in Sources */ = {isa = PBXBuildFile; fileRef = D0DF90AD2814390000FC0F64 /* BannerModel.m */; }; D0DF90AE2814390000FC0F64 /* BannerModel.m in Sources */ = {isa = PBXBuildFile; fileRef = D0DF90AD2814390000FC0F64 /* BannerModel.m */; };
...@@ -554,6 +557,12 @@ ...@@ -554,6 +557,12 @@
D0D69ED528236E0800A0D5EB /* SafeSleepListController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SafeSleepListController.m; sourceTree = "<group>"; }; D0D69ED528236E0800A0D5EB /* SafeSleepListController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SafeSleepListController.m; sourceTree = "<group>"; };
D0D7480328118D0B00036379 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Main.strings"; sourceTree = "<group>"; }; D0D7480328118D0B00036379 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Main.strings"; sourceTree = "<group>"; };
D0D7480428118D0B00036379 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/LaunchScreen.strings"; sourceTree = "<group>"; }; D0D7480428118D0B00036379 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/LaunchScreen.strings"; sourceTree = "<group>"; };
D0D96FDD2848457900461839 /* RelaxTrainRequestModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RelaxTrainRequestModel.h; sourceTree = "<group>"; };
D0D96FDE2848457900461839 /* RelaxTrainRequestModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RelaxTrainRequestModel.m; sourceTree = "<group>"; };
D0D96FE02848493700461839 /* RelaxTrainModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RelaxTrainModel.h; sourceTree = "<group>"; };
D0D96FE12848493700461839 /* RelaxTrainModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RelaxTrainModel.m; sourceTree = "<group>"; };
D0D96FE32848698E00461839 /* SomeProxy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SomeProxy.m; sourceTree = "<group>"; };
D0D96FE42848698F00461839 /* SomeProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SomeProxy.h; sourceTree = "<group>"; };
D0DB33A328204E7C00E15914 /* FirstLeadAlertView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FirstLeadAlertView.h; sourceTree = "<group>"; }; D0DB33A328204E7C00E15914 /* FirstLeadAlertView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FirstLeadAlertView.h; sourceTree = "<group>"; };
D0DB33A428204E7C00E15914 /* FirstLeadAlertView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FirstLeadAlertView.m; sourceTree = "<group>"; }; D0DB33A428204E7C00E15914 /* FirstLeadAlertView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FirstLeadAlertView.m; sourceTree = "<group>"; };
D0DB33A628224D5100E15914 /* PromotionModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PromotionModel.h; sourceTree = "<group>"; }; D0DB33A628224D5100E15914 /* PromotionModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PromotionModel.h; sourceTree = "<group>"; };
...@@ -788,11 +797,17 @@ ...@@ -788,11 +797,17 @@
D04567AC27F6D0BA009F0A82 /* AISleepModule */ = { D04567AC27F6D0BA009F0A82 /* AISleepModule */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
D0D96FE42848698F00461839 /* SomeProxy.h */,
D0D96FE32848698E00461839 /* SomeProxy.m */,
D04B3DB427F6F7430022F8DF /* AISleepCoach.storyboard */, D04B3DB427F6F7430022F8DF /* AISleepCoach.storyboard */,
D04B3DB927F6F7940022F8DF /* AISleepCoachController.h */, D04B3DB927F6F7940022F8DF /* AISleepCoachController.h */,
D04B3DBA27F6F7940022F8DF /* AISleepCoachController.m */, D04B3DBA27F6F7940022F8DF /* AISleepCoachController.m */,
D030C1B6284775930014946F /* RelaxTrainController.h */, D030C1B6284775930014946F /* RelaxTrainController.h */,
D030C1B7284775930014946F /* RelaxTrainController.m */, D030C1B7284775930014946F /* RelaxTrainController.m */,
D0D96FDD2848457900461839 /* RelaxTrainRequestModel.h */,
D0D96FDE2848457900461839 /* RelaxTrainRequestModel.m */,
D0D96FE02848493700461839 /* RelaxTrainModel.h */,
D0D96FE12848493700461839 /* RelaxTrainModel.m */,
); );
path = AISleepModule; path = AISleepModule;
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -1756,6 +1771,7 @@ ...@@ -1756,6 +1771,7 @@
D0B5ECD527F2F0B2003EDFE3 /* AdaptationUtil.m in Sources */, D0B5ECD527F2F0B2003EDFE3 /* AdaptationUtil.m in Sources */,
D070509A28071BAF006D72E1 /* DSNetworkTool.m in Sources */, D070509A28071BAF006D72E1 /* DSNetworkTool.m in Sources */,
D01814D127FFCBAF00583D4E /* CWCarousel.m in Sources */, D01814D127FFCBAF00583D4E /* CWCarousel.m in Sources */,
D0D96FE22848493700461839 /* RelaxTrainModel.m in Sources */,
D0B5ECB727F2D9E0003EDFE3 /* main.m in Sources */, D0B5ECB727F2D9E0003EDFE3 /* main.m in Sources */,
D0BE53742845B27E007F15B3 /* DailyTaskModel.m in Sources */, D0BE53742845B27E007F15B3 /* DailyTaskModel.m in Sources */,
D07DACA62810557D0067A1BF /* RSKTouchView.m in Sources */, D07DACA62810557D0067A1BF /* RSKTouchView.m in Sources */,
...@@ -1777,6 +1793,7 @@ ...@@ -1777,6 +1793,7 @@
D0E660022807B5AE006562F2 /* SafeSleepRequestModel.m in Sources */, D0E660022807B5AE006562F2 /* SafeSleepRequestModel.m in Sources */,
D0D4107C2844B8DB00009638 /* DailyTaskController.m in Sources */, D0D4107C2844B8DB00009638 /* DailyTaskController.m in Sources */,
D0E6600828080F97006562F2 /* SystemSetController.m in Sources */, D0E6600828080F97006562F2 /* SystemSetController.m in Sources */,
D0D96FE52848698F00461839 /* SomeProxy.m in Sources */,
D091BBB72808F9DA00487A50 /* BreathTextView.m in Sources */, D091BBB72808F9DA00487A50 /* BreathTextView.m in Sources */,
D08F79E1281A1838000D99DD /* TZLocationManager.m in Sources */, D08F79E1281A1838000D99DD /* TZLocationManager.m in Sources */,
D04B3DBB27F6F7940022F8DF /* AISleepCoachController.m in Sources */, D04B3DBB27F6F7940022F8DF /* AISleepCoachController.m in Sources */,
...@@ -1837,6 +1854,7 @@ ...@@ -1837,6 +1854,7 @@
D09BF337280E605900E5F06C /* NSObject+Extras.m in Sources */, D09BF337280E605900E5F06C /* NSObject+Extras.m in Sources */,
D055BEC528252B8900BC11A4 /* AudioDetailHeaderView.m in Sources */, D055BEC528252B8900BC11A4 /* AudioDetailHeaderView.m in Sources */,
D07DACA72810557D0067A1BF /* UIApplication+RSKImageCropper.m in Sources */, D07DACA72810557D0067A1BF /* UIApplication+RSKImageCropper.m in Sources */,
D0D96FDF2848457900461839 /* RelaxTrainRequestModel.m in Sources */,
D027EE2927FB51D0004BBA61 /* DSGifHeader.m in Sources */, D027EE2927FB51D0004BBA61 /* DSGifHeader.m in Sources */,
D030C1B8284775930014946F /* RelaxTrainController.m in Sources */, D030C1B8284775930014946F /* RelaxTrainController.m in Sources */,
D049679D2834E1AB00FB81E5 /* ProfileHeaderView.m in Sources */, D049679D2834E1AB00FB81E5 /* ProfileHeaderView.m in Sources */,
...@@ -2046,7 +2064,7 @@ ...@@ -2046,7 +2064,7 @@
CODE_SIGN_ENTITLEMENTS = DreamSleep/Basement/DSConfig/DreamSleepDebug.entitlements; CODE_SIGN_ENTITLEMENTS = DreamSleep/Basement/DSConfig/DreamSleepDebug.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer"; CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Manual; CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 4; CURRENT_PROJECT_VERSION = 5;
DEVELOPMENT_TEAM = 4NDZ6UX8PW; DEVELOPMENT_TEAM = 4NDZ6UX8PW;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
EXCLUDED_ARCHS = ""; EXCLUDED_ARCHS = "";
...@@ -2116,7 +2134,7 @@ ...@@ -2116,7 +2134,7 @@
CODE_SIGN_ENTITLEMENTS = DreamSleep/DreamSleep.entitlements; CODE_SIGN_ENTITLEMENTS = DreamSleep/DreamSleep.entitlements;
CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 4; CURRENT_PROJECT_VERSION = 5;
DEVELOPMENT_TEAM = 4NDZ6UX8PW; DEVELOPMENT_TEAM = 4NDZ6UX8PW;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = ( FRAMEWORK_SEARCH_PATHS = (
...@@ -2247,7 +2265,7 @@ ...@@ -2247,7 +2265,7 @@
CODE_SIGN_ENTITLEMENTS = DreamSleep/Basement/DSConfig/DreamSleepBeta.entitlements; CODE_SIGN_ENTITLEMENTS = DreamSleep/Basement/DSConfig/DreamSleepBeta.entitlements;
CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 4; CURRENT_PROJECT_VERSION = 5;
DEVELOPMENT_TEAM = 4NDZ6UX8PW; DEVELOPMENT_TEAM = 4NDZ6UX8PW;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = ( FRAMEWORK_SEARCH_PATHS = (
......
...@@ -8,8 +8,9 @@ ...@@ -8,8 +8,9 @@
#import "DsWebController.h" #import "DsWebController.h"
#import <WebKit/webKit.h> #import <WebKit/webKit.h>
#import "DsMaskView.h" #import "DsMaskView.h"
#import "SomeProxy.h"
@interface DsWebController () <WKNavigationDelegate> @interface DsWebController () <WKNavigationDelegate, WKScriptMessageHandler>
@property (nonatomic, copy) NSString *naviTitle; @property (nonatomic, copy) NSString *naviTitle;
@property (nonatomic, strong) NSURL *linkUrl; @property (nonatomic, strong) NSURL *linkUrl;
@property (nonatomic, assign) BOOL isShowNavi; @property (nonatomic, assign) BOOL isShowNavi;
...@@ -56,6 +57,7 @@ ...@@ -56,6 +57,7 @@
} }
- (void)dealloc { - (void)dealloc {
[self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"AppModel"];
[self.webView removeObserver:self forKeyPath:@"estimatedProgress"]; [self.webView removeObserver:self forKeyPath:@"estimatedProgress"];
} }
...@@ -69,6 +71,11 @@ ...@@ -69,6 +71,11 @@
return !self.isShowNavi; return !self.isShowNavi;
} }
#pragma mark - H5页面导航栏为默认模式
- (NaviStyle)navigationBarStyle {
return NaviStyleDefault;
}
#pragma mark - WKWebView的监听方法 #pragma mark - WKWebView的监听方法
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context { - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
if ([keyPath isEqualToString:@"estimatedProgress"]) { if ([keyPath isEqualToString:@"estimatedProgress"]) {
...@@ -97,10 +104,33 @@ ...@@ -97,10 +104,33 @@
self.exceptionView.hidden = NO; self.exceptionView.hidden = NO;
} }
#pragma mark - WKScriptMessageHandler
- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message {
if ([message.name isEqualToString:@"AppModel"]) {
NSDictionary *bodyDic = message.body;
int type = [bodyDic[@"type"] intValue];
DSLog(@"bodyDic:%@", bodyDic);
if (type == 88) { [self.navigationController popViewControllerAnimated:YES]; }
}
}
#pragma mark - lazy #pragma mark - lazy
- (WKWebView *)webView { - (WKWebView *)webView {
if (!_webView) { if (!_webView) {
_webView = [[WKWebView alloc] init]; // 进行配置控制器
WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
// 实例化对象
configuration.userContentController = [WKUserContentController new];
// 调用JS方法
[configuration.userContentController addScriptMessageHandler:[[SomeProxy alloc] initObject:self] name:@"AppModel"];
// 进行偏好设置
WKPreferences *preferences = [WKPreferences new];
preferences.javaScriptCanOpenWindowsAutomatically = NO;
preferences.javaScriptEnabled = YES;
configuration.preferences = preferences;
_webView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:configuration];
_webView.navigationDelegate = self; _webView.navigationDelegate = self;
_webView.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG); _webView.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
_webView.scrollView.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG); _webView.scrollView.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
...@@ -132,15 +162,10 @@ ...@@ -132,15 +162,10 @@
weakSelf.progressView.hidden = NO; weakSelf.progressView.hidden = NO;
weakSelf.progressView.progress = 0; weakSelf.progressView.progress = 0;
weakSelf.exceptionView.hidden = YES; weakSelf.exceptionView.hidden = YES;
[weakSelf.webView loadRequest:self.request]; [weakSelf.webView loadRequest:weakSelf.request];
} superView:self.view]; } superView:self.view];
} }
return _exceptionView; return _exceptionView;
} }
#pragma mark - H5页面导航栏为默认模式
- (NaviStyle)navigationBarStyle {
return NaviStyleDefault;
}
@end @end
...@@ -10,8 +10,6 @@ ...@@ -10,8 +10,6 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
// 用户服务协议和隐私政策 // 用户服务协议和隐私政策
FOUNDATION_EXTERN NSString * const UserServiceAgreement;
FOUNDATION_EXTERN NSString * const PrivacyPolicy;
FOUNDATION_EXTERN NSString * const PrivacyStatement; FOUNDATION_EXTERN NSString * const PrivacyStatement;
FOUNDATION_EXTERN NSString * const FirstShowPrivacy; FOUNDATION_EXTERN NSString * const FirstShowPrivacy;
...@@ -20,11 +18,6 @@ FOUNDATION_EXTERN NSString * const IsFirstGuide; ...@@ -20,11 +18,6 @@ FOUNDATION_EXTERN NSString * const IsFirstGuide;
// 首次启动APP进入主页弹框 // 首次启动APP进入主页弹框
FOUNDATION_EXTERN NSString * const IsFirstAlert; FOUNDATION_EXTERN NSString * const IsFirstAlert;
// 关于我们
FOUNDATION_EXTERN NSString * const AboutUS;
// 失眠的认知行为疗法
FOUNDATION_EXTERN NSString * const MYCBTI;
// 主题模式自动切换标记 // 主题模式自动切换标记
FOUNDATION_EXTERN NSString * const ThemeAutoSwitch; FOUNDATION_EXTERN NSString * const ThemeAutoSwitch;
FOUNDATION_EXTERN NSString * const StartTime1; FOUNDATION_EXTERN NSString * const StartTime1;
......
...@@ -7,17 +7,12 @@ ...@@ -7,17 +7,12 @@
#import "DSConstUtil.h" #import "DSConstUtil.h"
NSString * const UserServiceAgreement = @"https://www.cbti.cn/sleep/user/agreement";
NSString * const PrivacyPolicy = @"https://www.cbti.cn/sleep/user/privacy";
NSString * const PrivacyStatement = @"欢迎来到小梦睡眠,我们依据最新的监管要求更新了用户服务协议和隐私政策,请您知悉:\n 1.为提供相关基本功能及服务,我们会在您同意的前提下收集和使用必要的信息。\n2.使用本产品的过程中会请求相关权限,您可以选择是否授权该权限,也可以在隐私政策中了解详情。\n3.为确保相关功能服务的正常运行,您需要授权小梦睡眠APP获取设备Mac地址,您有权不同意该授权。\n4.未经您许可,小梦睡眠APP不会从第三方获取、提供或共享您的信息。\n可以点击阅读小梦睡眠APP用户服务协议和隐私政策的全部内容,感谢您的支持,欢迎问题反馈。"; NSString * const PrivacyStatement = @"欢迎来到小梦睡眠,我们依据最新的监管要求更新了用户服务协议和隐私政策,请您知悉:\n 1.为提供相关基本功能及服务,我们会在您同意的前提下收集和使用必要的信息。\n2.使用本产品的过程中会请求相关权限,您可以选择是否授权该权限,也可以在隐私政策中了解详情。\n3.为确保相关功能服务的正常运行,您需要授权小梦睡眠APP获取设备Mac地址,您有权不同意该授权。\n4.未经您许可,小梦睡眠APP不会从第三方获取、提供或共享您的信息。\n可以点击阅读小梦睡眠APP用户服务协议和隐私政策的全部内容,感谢您的支持,欢迎问题反馈。";
NSString * const FirstShowPrivacy = @"FirstShowPrivacy"; NSString * const FirstShowPrivacy = @"FirstShowPrivacy";
NSString * const IsFirstGuide = @"isFirstGuide"; NSString * const IsFirstGuide = @"isFirstGuide";
NSString * const IsFirstAlert = @"isFirstAlert"; NSString * const IsFirstAlert = @"isFirstAlert";
NSString * const AboutUS = @"https://www.cbti.cn/sleep/user/about";
NSString * const MYCBTI = @"https://www.cbti.cn/sleep/ssmian/cbti";
NSString * const ThemeAutoSwitch = @"themeAutoSwitch"; NSString * const ThemeAutoSwitch = @"themeAutoSwitch";
NSString * const StartTime1 = @"21:00:00"; NSString * const StartTime1 = @"21:00:00";
NSString * const ExpireTime1 = @"23:59:59"; NSString * const ExpireTime1 = @"23:59:59";
......
...@@ -14,9 +14,17 @@ ...@@ -14,9 +14,17 @@
// AI睡眠教练接口地址 // AI睡眠教练接口地址
#define AICoachURL [NSString stringWithFormat:@"%@/%@", ServerURL, @"sleep/ai/sleep_aicocah"] #define AICoachURL [NSString stringWithFormat:@"%@/%@", ServerURL, @"sleep/ai/sleep_aicocah"]
// 我的睡眠报告地址 // 我的睡眠报告地址
#define MySleepReportURL [ServerURL stringByAppendingPathComponent:@"sleep/ssmian/sleep_diary?step=10"] #define MySleepReportURL [NSString stringWithFormat:@"%@/%@", ServerURL, @"sleep/ssmian/sleep_diary?step=10"]
// 我的睡眠评测 // 我的睡眠评测
#define MySleepReviewURL [ServerURL stringByAppendingPathComponent:@"sleep/ssmian/history_report?type_id=101&step=10"] #define MySleepReviewURL [NSString stringWithFormat:@"%@/%@", ServerURL, @"sleep/ssmian/history_report?type_id=101&step=10"]
// CBTI
#define MYCBTI [NSString stringWithFormat:@"%@/%@", ServerURL, @"sleep/ssmian/cbti"]
// 关于我们
#define AboutUS [NSString stringWithFormat:@"%@/%@", ServerURL, @"sleep/user/about"]
// 用户协议
#define UserServiceAgreement [NSString stringWithFormat:@"%@/%@", ServerURL, @"sleep/user/agreement"]
// 隐私政策
#define PrivacyPolicy [NSString stringWithFormat:@"%@/%@", ServerURL, @"sleep/user/privacy"]
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
......
...@@ -8,12 +8,15 @@ ...@@ -8,12 +8,15 @@
#import "AISleepCoachController.h" #import "AISleepCoachController.h"
#import <WebKit/WebKit.h> #import <WebKit/WebKit.h>
#import <JavaScriptCore/JavaScriptCore.h> #import <JavaScriptCore/JavaScriptCore.h>
#import "RelaxTrainController.h"
#import "SomeProxy.h"
#import "ThreeMinuteController.h"
@interface AISleepCoachController () <WKNavigationDelegate, WKScriptMessageHandler, WKUIDelegate> @interface AISleepCoachController () <WKNavigationDelegate, WKScriptMessageHandler>
@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;
@property (nonatomic, strong) ExceptionDefaultView *exceptionView; @property (strong, nonatomic) ExceptionDefaultView *exceptionView;
@end @end
@implementation AISleepCoachController @implementation AISleepCoachController
...@@ -30,6 +33,7 @@ ...@@ -30,6 +33,7 @@
} }
- (void)dealloc { - (void)dealloc {
[self.aiWebView.configuration.userContentController removeScriptMessageHandlerForName:@"AppModel"];
[self.aiWebView removeObserver:self forKeyPath:@"estimatedProgress"]; [self.aiWebView removeObserver:self forKeyPath:@"estimatedProgress"];
[[NSNotificationCenter defaultCenter] removeObserver:self name:NeedUpdateAICoach object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:NeedUpdateAICoach object:nil];
} }
...@@ -58,6 +62,8 @@ ...@@ -58,6 +62,8 @@
} else { } else {
[self.aiWebView removeMask]; [self.aiWebView removeMask];
} }
[self.aiWebView reload];
} }
#pragma mark - 登录成功后刷新 #pragma mark - 登录成功后刷新
...@@ -82,6 +88,11 @@ ...@@ -82,6 +88,11 @@
} }
} }
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
RelaxTrainController *relaxVC = [RelaxTrainController new];
[self.navigationController pushViewController:relaxVC animated:YES];
}
#pragma mark - WKWebView的监听方法 #pragma mark - WKWebView的监听方法
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context { - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
if ([keyPath isEqualToString:@"estimatedProgress"]) { if ([keyPath isEqualToString:@"estimatedProgress"]) {
...@@ -95,11 +106,13 @@ ...@@ -95,11 +106,13 @@
#pragma mark - WKNavigationDelegate #pragma mark - WKNavigationDelegate
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(nonnull WKNavigationAction *)navigationAction decisionHandler:(nonnull void (^)(WKNavigationActionPolicy))decisionHandler { - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(nonnull WKNavigationAction *)navigationAction decisionHandler:(nonnull void (^)(WKNavigationActionPolicy))decisionHandler {
NSString *url = navigationAction.request.URL.absoluteString; NSString *url = navigationAction.request.URL.absoluteString;
DSLog(@"跳转链接:%@", url);
if ([url isEqualToString:AICoachURL]) { if ([url isEqualToString:AICoachURL]) {
decisionHandler(WKNavigationActionPolicyAllow); decisionHandler(WKNavigationActionPolicyAllow);
} else { } else {
// 开启新的webview页面加载 // 开启新的webview页面加载
[self.navigationController pushViewController:[[DsWebController alloc] initWithLink:url isShowNavi:YES] animated:YES]; [self.navigationController pushViewController:[[DsWebController alloc] initWithLink:url isShowNavi:NO] animated:YES];
decisionHandler(WKNavigationActionPolicyCancel); decisionHandler(WKNavigationActionPolicyCancel);
} }
} }
...@@ -127,11 +140,32 @@ ...@@ -127,11 +140,32 @@
- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message { - (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message {
if ([message.name isEqualToString:@"AppModel"]) { if ([message.name isEqualToString:@"AppModel"]) {
NSDictionary *bodyDic = message.body; NSDictionary *bodyDic = message.body;
DSLog(@"bodyDic:%@", bodyDic);
int type = [bodyDic[@"type"] intValue]; int type = [bodyDic[@"type"] intValue];
if (type == 1) { // 未登录点击开启 DSLog(@"bodyDic:%@", bodyDic);
switch (type) {
case 1: // 未登录点击开启
{
[self startOpen]; [self startOpen];
}
break;
case 2: // 登录点击开启-开启我的页面里面的AI睡眠教练
{
}
break;
case 3: // 轻拍哄睡
{
[self.navigationController pushViewController:[ThreeMinuteController new] animated:YES];
}
break;
case 4: // 安心记事本
{
[DSProgressHUD showToast:@"该功能未来会被替换"];
}
break;
default:
break;
}
// 注入js代码用于强制刷新小梦睡眠 // 注入js代码用于强制刷新小梦睡眠
// NSString *jsCallBack = @"window.parent.location.reload()"; // NSString *jsCallBack = @"window.parent.location.reload()";
...@@ -143,7 +177,6 @@ ...@@ -143,7 +177,6 @@
// } // }
// }]; // }];
} }
}
} }
#pragma mark - lazy #pragma mark - lazy
...@@ -154,7 +187,7 @@ ...@@ -154,7 +187,7 @@
// 实例化对象 // 实例化对象
configuration.userContentController = [WKUserContentController new]; configuration.userContentController = [WKUserContentController new];
// 调用JS方法 // 调用JS方法
[configuration.userContentController addScriptMessageHandler:self name:@"AppModel"]; [configuration.userContentController addScriptMessageHandler:[[SomeProxy alloc] initObject:self] name:@"AppModel"];
// 进行偏好设置 // 进行偏好设置
WKPreferences *preferences = [WKPreferences new]; WKPreferences *preferences = [WKPreferences new];
...@@ -163,9 +196,8 @@ ...@@ -163,9 +196,8 @@
configuration.preferences = preferences; configuration.preferences = preferences;
// 初始化WKWebView // 初始化WKWebView
_aiWebView = [[WKWebView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - kTabBarHeight) configuration:configuration]; _aiWebView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - kTabBarHeight) configuration:configuration];
_aiWebView.backgroundColor = DSWhite; _aiWebView.backgroundColor = DSWhite;
_aiWebView.UIDelegate = self;
_aiWebView.hidden = YES; _aiWebView.hidden = YES;
_aiWebView.scrollView.bounces = NO; _aiWebView.scrollView.bounces = NO;
[_aiWebView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil]; [_aiWebView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil];
...@@ -197,7 +229,7 @@ ...@@ -197,7 +229,7 @@
weakSelf.progressView.hidden = NO; weakSelf.progressView.hidden = NO;
weakSelf.progressView.progress = 0; weakSelf.progressView.progress = 0;
weakSelf.exceptionView.hidden = YES; weakSelf.exceptionView.hidden = YES;
[weakSelf.aiWebView loadRequest:self.request]; [weakSelf.aiWebView loadRequest:weakSelf.request];
} superView:self.view]; } superView:self.view];
} }
return _exceptionView; return _exceptionView;
......
...@@ -6,9 +6,12 @@ ...@@ -6,9 +6,12 @@
// //
#import "RelaxTrainController.h" #import "RelaxTrainController.h"
#import "RelaxTrainRequestModel.h"
@interface RelaxTrainController () @interface RelaxTrainController ()
@property (nonatomic, strong) UIImageView *bgIV;
@property (nonatomic, strong) UILabel *cusTitleLab;
@property (nonatomic, strong) NSArray *listArr;
@end @end
@implementation RelaxTrainController @implementation RelaxTrainController
...@@ -16,15 +19,66 @@ ...@@ -16,15 +19,66 @@
- (void)viewDidLoad { - (void)viewDidLoad {
[super viewDidLoad]; [super viewDidLoad];
/* self.view.backgroundColor = DSWhite;
https://lanhuapp.com/url/f7vOH-utG5Q [self.view addSubview:self.bgIV];
[self.view addSubview:self.dsNaviBar];
[self.view addSubview:self.dkBackBtn];
[self.dkBackBtn dk_setImage:DKImagePickerWithNames(@"cus_back_icon", @"cus_back_icon", @"dk_cus_back_icon") forState:UIControlStateNormal];
[self.view addSubview:self.cusTitleLab];
[RelaxTrainRequestModel queryRelaxAudioListWithCompletion:^(RelaxTrainRequestModel * _Nonnull requestModel) {
if (requestModel.resCode == DSResCodeSuccess) {
if (requestModel.trainAudioList.count) {
self.listArr = requestModel.trainAudioList;
RelaxTrainModel *currentModel = requestModel.trainAudioList.firstObject;
[self.bgIV setImageWithURL:[NSURL URLWithString:currentModel.bg_url] placeholderImage:[UIImage imageNamed:@"basicPlaceholder"]];
self.cusTitleLab.text = currentModel.audio_name;
}
}
}];
[RelaxTrainRequestModel userCurTaskStateWithParams:@{@"title":@"腹式呼吸放松法", @"step":@2} completion:^(RelaxTrainRequestModel * _Nonnull requestModel) {
}];
CGFloat iv_h = kScreenWidth*1233/1125.0;
[self.bgIV mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.right.equalTo(self.view);
make.height.equalTo(@(iv_h));
}];
[self.cusTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.dsNaviBar);
make.bottom.equalTo(self.dsNaviBar).offset(-9);
}];
}
公司wifi 密码aolei@yidingniu.com #pragma mark - Actions
- (void)backAction {
[super backAction];
[self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - lazy
- (UIImageView *)bgIV {
if (!_bgIV) {
_bgIV = [UIImageView new];
}
return _bgIV;
}
- (UILabel *)cusTitleLab {
if (!_cusTitleLab) {
_cusTitleLab = [UILabel labWithTextColor:MainTextColor font:BoldFont(18)];
_cusTitleLab.textAlignment = NSTextAlignmentCenter;
}
return _cusTitleLab;
}
2、练习腹式呼吸法功能接口: - (NSArray *)listArr {
query_relax_audio_list if (!_listArr) {
user_cur_task_state _listArr = [NSArray array];
*/ }
return _listArr;
} }
@end @end
//
// RelaxTrainModel.h
// DreamSleep
//
// Created by peter on 2022/6/2.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/// 放松训练数据model
@interface RelaxTrainModel : NSObject
/// 音频id
@property (nonatomic, assign) int audio_id;
/// 播放背景图
@property (nonatomic, copy) NSString *bg_url;
/// 音频封面
@property (nonatomic, copy) NSString *audio_img;
/// 音频名称
@property (nonatomic, copy) NSString *audio_name;
/// 音频播放链接
@property (nonatomic, copy) NSString *audio_url;
/// 是否推荐(1:推荐,0:不推荐)
@property (nonatomic, copy) NSString *is_recommend;
/// 描述信息
@property (nonatomic, copy) NSString *audio_desc;
@end
NS_ASSUME_NONNULL_END
//
// RelaxTrainModel.m
// DreamSleep
//
// Created by peter on 2022/6/2.
//
#import "RelaxTrainModel.h"
@implementation RelaxTrainModel
+ (nullable NSDictionary<NSString *, id> *)modelCustomPropertyMapper {
return @{@"audio_id" : @"id"};
}
@end
//
// RelaxTrainRequestModel.h
// DreamSleep
//
// Created by peter on 2022/6/2.
//
#import "DSNetworkTool.h"
#import "RelaxTrainModel.h"
NS_ASSUME_NONNULL_BEGIN
@interface RelaxTrainRequestModel : DSNetworkTool
/// 训练音频列表
@property (nonatomic, strong) NSArray *trainAudioList;
/// 获取放松音频列表数据
/// @param completion completion
+ (NSURLSessionDataTask *)queryRelaxAudioListWithCompletion:(void (^)(RelaxTrainRequestModel *requestModel))completion;
/// 睡眠-AI教练任务更新操作步骤接口
/// @param params @{@"title":xxx, @"step":xxx}
/// @param completion completion
+ (NSURLSessionDataTask *)userCurTaskStateWithParams:(NSDictionary *)params completion:(void (^)(RelaxTrainRequestModel *requestModel))completion;
@end
NS_ASSUME_NONNULL_END
//
// RelaxTrainRequestModel.m
// DreamSleep
//
// Created by peter on 2022/6/2.
//
#import "RelaxTrainRequestModel.h"
@implementation RelaxTrainRequestModel
+ (NSURLSessionDataTask *)queryRelaxAudioListWithCompletion:(void (^)(RelaxTrainRequestModel *requestModel))completion
{
RelaxTrainRequestModel * requestModel = [[RelaxTrainRequestModel alloc] init];
NSString *api = @"query_relax_audio_list";
NSString *argStr = [NSString stringWithFormat:@"query{%@}", api];
return [self httpPostBodyRequestWithAPI:api params:@{@"query" : argStr} view:nil hasNetActivity:YES loadingInfo:nil hasFailInfo:YES success:^(NSDictionary * _Nonnull apiDic) {
DSLog(@"获取放松音频列表数据接口apiDic:%@", apiDic);
requestModel.resCode = DSResCodeSuccess;
NSArray *resultArr = apiDic[@"result"];
NSMutableArray *tmpArr = [NSMutableArray array];
for (NSDictionary *audioDic in resultArr) {
RelaxTrainModel *trainModel = [RelaxTrainModel yy_modelWithDictionary:audioDic];
[tmpArr addObject:trainModel];
}
requestModel.trainAudioList = [tmpArr copy];
completion(requestModel);
} failure:^(id _Nonnull failureInfo) {
requestModel.resCode = DSResCodeNetFail;
requestModel.errorInfo = failureInfo;
completion(requestModel);
}];
}
+ (NSURLSessionDataTask *)userCurTaskStateWithParams:(NSDictionary *)params completion:(void (^)(RelaxTrainRequestModel *requestModel))completion {
RelaxTrainRequestModel * requestModel = [[RelaxTrainRequestModel alloc] init];
NSString *api = @"user_cur_task_state";
NSString *title = params[@"title"];
int step = [params[@"step"] intValue];
NSString *argStr = [NSString stringWithFormat:@"mutation{%@(title:\"%@\",step:%d)}", api, title, step];
return [self httpPostBodyRequestWithAPI:api params:@{@"query" : argStr} view:nil hasNetActivity:YES loadingInfo:nil hasFailInfo:YES success:^(NSDictionary * _Nonnull apiDic) {
DSLog(@"睡眠-AI教练任务更新操作步骤接口apiDic:%@", apiDic);
requestModel.resCode = DSResCodeSuccess;
completion(requestModel);
} failure:^(id _Nonnull failureInfo) {
requestModel.resCode = DSResCodeNetFail;
requestModel.errorInfo = failureInfo;
completion(requestModel);
}];
}
@end
//
// SomeProxy.h
// test1
//
// Created by Xu小波 on 2020/3/24.
// Copyright © 2020 Xu小波. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <WebKit/WebKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface SomeProxy : NSProxy<WKScriptMessageHandler>
- (instancetype)initObject:(id)obj;
@end
NS_ASSUME_NONNULL_END
//
// SomeProxy.m
// test1
//
// Created by Xu小波 on 2020/3/24.
// Copyright © 2020 Xu小波. All rights reserved.
//
#import "SomeProxy.h"
#import <WebKit/WebKit.h>
@interface SomeProxy ()
@property (nonatomic, weak) id obj;
@end
@implementation SomeProxy
- (void)dealloc {
DSLog(@"SomeProxy - dealloc");
}
- (instancetype)initObject:(id)obj {
self.obj = obj;
return self;
}
- (void)forwardInvocation:(NSInvocation *)invocation {
if ([self.obj respondsToSelector:invocation.selector]) {
[invocation invokeWithTarget:self.obj];
}
}
- (nullable NSMethodSignature *)methodSignatureForSelector:(SEL)sel {
return [self.obj methodSignatureForSelector:sel];
}
@end
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
@interface CourseDetailController () <UITableViewDelegate, UITableViewDataSource> @interface CourseDetailController () <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UITableView *audioListView; @property (nonatomic, strong) UITableView *audioListView;
@property (nonatomic,strong) NSArray *subAudioArr; @property (nonatomic, strong) NSArray *subAudioArr;
@property (nonatomic,strong) UIButton *unlockBtn; @property (nonatomic, strong) UIButton *unlockBtn;
@end @end
@implementation CourseDetailController @implementation CourseDetailController
......
...@@ -82,7 +82,7 @@ ...@@ -82,7 +82,7 @@
BannerModel *model = self.bannerDatas[index]; BannerModel *model = self.bannerDatas[index];
switch (model.banner_id) { switch (model.banner_id) {
case 13: { // 进入失眠拯救计划页面 case 13: { // 进入失眠拯救计划页面
[self.ds_viewController.navigationController pushViewController:[[DsWebController alloc] initWithTitle:@"失眠拯救计划" link:model.info_url] animated:YES]; [self.ds_viewController.navigationController pushViewController:[[DsWebController alloc] initWithLink:model.info_url isShowNavi:NO] animated:YES];
} }
break; break;
case 11: { // 切换到AI睡眠教练标签 case 11: { // 切换到AI睡眠教练标签
...@@ -90,12 +90,11 @@ ...@@ -90,12 +90,11 @@
} }
break; break;
case 10: { // 进入三分钟即刻入睡页面 case 10: { // 进入三分钟即刻入睡页面
ThreeMinuteController *threeVC = [[ThreeMinuteController alloc] init]; [self.ds_viewController.navigationController pushViewController:[ThreeMinuteController new] animated:YES];
[self.ds_viewController.navigationController pushViewController:threeVC animated:YES];
} }
break; break;
case 8: { // 进入睡眠评测页面 case 8: { // 进入睡眠评测页面
[self.ds_viewController.navigationController pushViewController:[[DsWebController alloc] initWithTitle:@"睡眠评测" link:model.info_url] animated:YES]; [self.ds_viewController.navigationController pushViewController:[[DsWebController alloc] initWithLink:model.info_url isShowNavi:NO] animated:YES];
} }
break; break;
default: default:
......
...@@ -112,12 +112,12 @@ ...@@ -112,12 +112,12 @@
break; break;
case 4: // 我的睡眠报告 case 4: // 我的睡眠报告
{ {
[self.navigationController pushViewController:[[DsWebController alloc] initWithLink:MySleepReportURL isShowNavi:YES] animated:YES]; [self.navigationController pushViewController:[[DsWebController alloc] initWithLink:MySleepReportURL isShowNavi:NO] animated:YES];
} }
break; break;
case 5: // 我的睡眠评测 case 5: // 我的睡眠评测
{ {
[self.navigationController pushViewController:[[DsWebController alloc] initWithLink:MySleepReviewURL isShowNavi:YES] animated:YES]; [self.navigationController pushViewController:[[DsWebController alloc] initWithLink:MySleepReviewURL isShowNavi:NO] animated:YES];
} }
break; break;
default: default:
......
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
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 = YES; self.openAIBtn.hidden = YES;
self.reportReviewsView.hidden = NO; self.reportReviewsView.hidden = NO;
self.scoreCountLab.text = [NSString stringWithFormat:@"我的积分:%d", model.total_points]; self.scoreCountLab.text = [NSString stringWithFormat:@"我的积分:%d", model.total_points];
......
...@@ -213,7 +213,7 @@ ...@@ -213,7 +213,7 @@
#pragma mark - Action #pragma mark - Action
- (void)tapCBTIAction { - (void)tapCBTIAction {
[self.ds_viewController.navigationController pushViewController:[[DsWebController alloc] initWithTitle:@"失眠的认知行为疗法(CBTI)" link:MYCBTI] animated:YES]; [self.ds_viewController.navigationController pushViewController:[[DsWebController alloc] initWithLink:MYCBTI isShowNavi:NO] animated:YES];
} }
#pragma mark - ProfileHeaderViewDelegate #pragma mark - ProfileHeaderViewDelegate
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!