Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
陈高翔
/
DreamSleep-iOS
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 97eb5f59
由
cgx
编写于
2022-05-25 10:00:05 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
完成AI睡眠教练登录
1 个父辈
d488a623
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
48 行增加
和
34 行删除
DreamSleep/DreamSleep.xcodeproj/project.pbxproj
DreamSleep/DreamSleep/Class/AISleepModule/AISleepCoachController.m
DreamSleep/DreamSleep.xcodeproj/project.pbxproj
查看文件 @
97eb5f5
...
@@ -122,6 +122,7 @@
...
@@ -122,6 +122,7 @@
D09D0E96280D3FE9008DEDAB /* NSDate+Extras.m in Sources */ = {isa = PBXBuildFile; fileRef = D09D0E95280D3FE9008DEDAB /* NSDate+Extras.m */; };
D09D0E96280D3FE9008DEDAB /* NSDate+Extras.m in Sources */ = {isa = PBXBuildFile; fileRef = D09D0E95280D3FE9008DEDAB /* NSDate+Extras.m */; };
D09D0E9A280D507F008DEDAB /* ProfileAlertView.m in Sources */ = {isa = PBXBuildFile; fileRef = D09D0E99280D507F008DEDAB /* ProfileAlertView.m */; };
D09D0E9A280D507F008DEDAB /* ProfileAlertView.m in Sources */ = {isa = PBXBuildFile; fileRef = D09D0E99280D507F008DEDAB /* ProfileAlertView.m */; };
D09D0E9D280D73B6008DEDAB /* InviteController.m in Sources */ = {isa = PBXBuildFile; fileRef = D09D0E9C280D73B6008DEDAB /* InviteController.m */; };
D09D0E9D280D73B6008DEDAB /* InviteController.m in Sources */ = {isa = PBXBuildFile; fileRef = D09D0E9C280D73B6008DEDAB /* InviteController.m */; };
D0A245F6283DB12100FB49AA /* WKWebView+Extras.m in Sources */ = {isa = PBXBuildFile; fileRef = D0A245F5283DB12100FB49AA /* WKWebView+Extras.m */; };
D0A72E39282B566200EED7BE /* HomeBasicCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D0A72E38282B566200EED7BE /* HomeBasicCell.m */; };
D0A72E39282B566200EED7BE /* HomeBasicCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D0A72E38282B566200EED7BE /* HomeBasicCell.m */; };
D0A72E3C282B56E600EED7BE /* GoodSleepSoundCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D0A72E3B282B56E600EED7BE /* GoodSleepSoundCell.m */; };
D0A72E3C282B56E600EED7BE /* GoodSleepSoundCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D0A72E3B282B56E600EED7BE /* GoodSleepSoundCell.m */; };
D0A72E3F282B89AD00EED7BE /* DSHomeView.m in Sources */ = {isa = PBXBuildFile; fileRef = D0A72E3E282B89AD00EED7BE /* DSHomeView.m */; };
D0A72E3F282B89AD00EED7BE /* DSHomeView.m in Sources */ = {isa = PBXBuildFile; fileRef = D0A72E3E282B89AD00EED7BE /* DSHomeView.m */; };
...
@@ -427,6 +428,8 @@
...
@@ -427,6 +428,8 @@
D09D0E99280D507F008DEDAB /* ProfileAlertView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ProfileAlertView.m; sourceTree = "<group>"; };
D09D0E99280D507F008DEDAB /* ProfileAlertView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ProfileAlertView.m; sourceTree = "<group>"; };
D09D0E9B280D73B6008DEDAB /* InviteController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = InviteController.h; sourceTree = "<group>"; };
D09D0E9B280D73B6008DEDAB /* InviteController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = InviteController.h; sourceTree = "<group>"; };
D09D0E9C280D73B6008DEDAB /* InviteController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = InviteController.m; sourceTree = "<group>"; };
D09D0E9C280D73B6008DEDAB /* InviteController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = InviteController.m; sourceTree = "<group>"; };
D0A245F4283DB12100FB49AA /* WKWebView+Extras.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "WKWebView+Extras.h"; sourceTree = "<group>"; };
D0A245F5283DB12100FB49AA /* WKWebView+Extras.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "WKWebView+Extras.m"; sourceTree = "<group>"; };
D0A72E37282B566200EED7BE /* HomeBasicCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HomeBasicCell.h; sourceTree = "<group>"; };
D0A72E37282B566200EED7BE /* HomeBasicCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HomeBasicCell.h; sourceTree = "<group>"; };
D0A72E38282B566200EED7BE /* HomeBasicCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HomeBasicCell.m; sourceTree = "<group>"; };
D0A72E38282B566200EED7BE /* HomeBasicCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HomeBasicCell.m; sourceTree = "<group>"; };
D0A72E3A282B56E600EED7BE /* GoodSleepSoundCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GoodSleepSoundCell.h; sourceTree = "<group>"; };
D0A72E3A282B56E600EED7BE /* GoodSleepSoundCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GoodSleepSoundCell.h; sourceTree = "<group>"; };
...
@@ -682,6 +685,8 @@
...
@@ -682,6 +685,8 @@
D09D0E95280D3FE9008DEDAB /* NSDate+Extras.m */,
D09D0E95280D3FE9008DEDAB /* NSDate+Extras.m */,
D09BF335280E605900E5F06C /* NSObject+Extras.h */,
D09BF335280E605900E5F06C /* NSObject+Extras.h */,
D09BF336280E605900E5F06C /* NSObject+Extras.m */,
D09BF336280E605900E5F06C /* NSObject+Extras.m */,
D0A245F4283DB12100FB49AA /* WKWebView+Extras.h */,
D0A245F5283DB12100FB49AA /* WKWebView+Extras.m */,
);
);
path = Category;
path = Category;
sourceTree = "<group>";
sourceTree = "<group>";
...
@@ -1665,6 +1670,7 @@
...
@@ -1665,6 +1670,7 @@
D0FAC422281B817D00D4B859 /* GKPanGestureRecognizer.m in Sources */,
D0FAC422281B817D00D4B859 /* GKPanGestureRecognizer.m in Sources */,
D07DACA82810557D0067A1BF /* RSKImageCropViewController.m in Sources */,
D07DACA82810557D0067A1BF /* RSKImageCropViewController.m in Sources */,
D0E65FFB2807A654006562F2 /* NSDictionary+HYBUnicodeReadable.m in Sources */,
D0E65FFB2807A654006562F2 /* NSDictionary+HYBUnicodeReadable.m in Sources */,
D0A245F6283DB12100FB49AA /* WKWebView+Extras.m in Sources */,
D0E65FFA2807A654006562F2 /* NSArray+HYBUnicodeReadable.m in Sources */,
D0E65FFA2807A654006562F2 /* NSArray+HYBUnicodeReadable.m in Sources */,
D08F79DE281A1838000D99DD /* TZPhotoPickerController.m in Sources */,
D08F79DE281A1838000D99DD /* TZPhotoPickerController.m in Sources */,
D04B3DC027F6F82D0022F8DF /* ProfileController.m in Sources */,
D04B3DC027F6F82D0022F8DF /* ProfileController.m in Sources */,
...
...
DreamSleep/DreamSleep/Class/AISleepModule/AISleepCoachController.m
查看文件 @
97eb5f5
...
@@ -14,6 +14,7 @@
...
@@ -14,6 +14,7 @@
@property
(
strong
,
nonatomic
)
WKWebView
*
aiWebView
;
@property
(
strong
,
nonatomic
)
WKWebView
*
aiWebView
;
@property
(
strong
,
nonatomic
)
NSURLRequest
*
request
;
@property
(
strong
,
nonatomic
)
NSURLRequest
*
request
;
@property
(
strong
,
nonatomic
)
UIProgressView
*
progressView
;
@property
(
strong
,
nonatomic
)
UIProgressView
*
progressView
;
@property
(
nonatomic
,
strong
)
ExceptionDefaultView
*
exceptionView
;
@end
@end
@implementation
AISleepCoachController
@implementation
AISleepCoachController
...
@@ -44,6 +45,11 @@
...
@@ -44,6 +45,11 @@
return
YES
;
return
YES
;
}
}
#pragma mark - 品牌模式
-
(
NaviStyle
)
navigationBarStyle
{
return
NaviStyleDefault
;
}
-
(
void
)
viewWillAppear
:
(
BOOL
)
animated
{
-
(
void
)
viewWillAppear
:
(
BOOL
)
animated
{
[
super
viewWillAppear
:
animated
];
[
super
viewWillAppear
:
animated
];
...
@@ -55,23 +61,24 @@
...
@@ -55,23 +61,24 @@
}
}
}
}
#pragma mark - js和oc交互
#pragma mark - 登录成功后刷新
-
(
void
)
needUpdateAiCoach
{
[
WKWebView
deleteWebCache
];
// 延迟的时间
int64_t
delayInSeconds
=
2
.
0
;
[[
UIApplication
sharedApplication
]
setNetworkActivityIndicatorVisible
:
YES
];
dispatch_after
(
dispatch_time
(
DISPATCH_TIME_NOW
,
(
int64_t
)(
delayInSeconds
*
NSEC_PER_SEC
)),
dispatch_get_main_queue
(),
^
{
[
self
.
aiWebView
reload
];
});
}
-
(
void
)
startOpen
{
-
(
void
)
startOpen
{
if
(
!
[
LoginUtils
getUserLoginData
])
{
if
(
!
[
LoginUtils
getUserLoginData
])
{
[
LoginUtils
jumpToLoginControllerWithTarget
:
self
];
[
LoginUtils
jumpToLoginControllerWithTarget
:
self
];
}
}
}
}
-
(
void
)
touchesBegan
:
(
NSSet
<
UITouch
*>
*
)
touches
withEvent
:
(
UIEvent
*
)
event
{
[
self
.
aiWebView
reload
];
}
#pragma mark - 登录成功后刷新
-
(
void
)
needUpdateAiCoach
{
[
WKWebView
deleteWebCache
];
[
self
.
aiWebView
reload
];
}
#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"
])
{
...
@@ -91,32 +98,22 @@
...
@@ -91,32 +98,22 @@
// 加载成功
// 加载成功
-
(
void
)
webView
:
(
WKWebView
*
)
webView
didFinishNavigation
:
(
WKNavigation
*
)
navigation
{
-
(
void
)
webView
:
(
WKWebView
*
)
webView
didFinishNavigation
:
(
WKNavigation
*
)
navigation
{
[[
UIApplication
sharedApplication
]
setNetworkActivityIndicatorVisible
:
NO
];
[[
UIApplication
sharedApplication
]
setNetworkActivityIndicatorVisible
:
NO
];
self
.
exceptionView
.
hidden
=
YES
;
self
.
aiWebView
.
hidden
=
NO
;
}
}
// 加载失败
// 加载失败
-
(
void
)
webView
:
(
WKWebView
*
)
webView
didFailProvisionalNavigation
:
(
WKNavigation
*
)
navigation
withError
:
(
NSError
*
)
error
{
-
(
void
)
webView
:
(
WKWebView
*
)
webView
didFailProvisionalNavigation
:
(
WKNavigation
*
)
navigation
withError
:
(
NSError
*
)
error
{
[[
UIApplication
sharedApplication
]
setNetworkActivityIndicatorVisible
:
NO
];
[[
UIApplication
sharedApplication
]
setNetworkActivityIndicatorVisible
:
NO
];
DSLog
(
@"百度主页加载失败:%@"
,
error
.
userInfo
);
self
.
exceptionView
.
hidden
=
NO
;
}
DSLog
(
@"加载失败:%@"
,
error
);
//iOS端 wkwebview代理方法
-
(
void
)
webView
:
(
WKWebView
*
)
webView
decidePolicyForNavigationAction
:
(
WKNavigationAction
*
)
navigationAction
decisionHandler
:
(
void
(
^
)(
WKNavigationActionPolicy
))
decisionHandler
{
if
([
navigationAction
.
request
.
URL
.
absoluteString
isEqualToString
:
@"xc://scan"
])
{
//调用原生扫描二维码
decisionHandler
(
WKNavigationActionPolicyCancel
);
return
;
}
decisionHandler
(
WKNavigationActionPolicyAllow
);
}
}
-
(
void
)
userContentController
:
(
WKUserContentController
*
)
userContentController
didReceiveScriptMessage
:
(
WKScriptMessage
*
)
message
{
-
(
void
)
userContentController
:
(
WKUserContentController
*
)
userContentController
didReceiveScriptMessage
:
(
WKScriptMessage
*
)
message
{
if
([
message
.
name
isEqualToString
:
@"AppModel"
])
{
if
([
message
.
name
isEqualToString
:
@"AppModel"
])
{
// 打印所传过来的参数,只支持NSNumber, NSString, NSDate, NSArray,
// NSDictionary, and NSNull类型
NSDictionary
*
bodyDic
=
message
.
body
;
NSDictionary
*
bodyDic
=
message
.
body
;
DSLog
(
@"
message.body:%@, type:%d"
,
bodyDic
,
[
bodyDic
[
@"type"
]
intValue
]
);
DSLog
(
@"
bodyDic:%@"
,
bodyDic
);
int
type
=
[
bodyDic
[
@"type"
]
intValue
];
int
type
=
[
bodyDic
[
@"type"
]
intValue
];
if
(
type
==
1
)
{
// 未登录点击开启
if
(
type
==
1
)
{
// 未登录点击开启
[
self
startOpen
];
[
self
startOpen
];
...
@@ -140,17 +137,17 @@
...
@@ -140,17 +137,17 @@
// }
// }
}
}
// js调用alert
-
(
void
)
webView
:
(
WKWebView
*
)
webView
runJavaScriptAlertPanelWithMessage
:
(
NSString
*
)
message
initiatedByFrame
:
(
WKFrameInfo
*
)
frame
completionHandler
:
(
void
(
^
)(
void
))
completionHandler
{
-
(
void
)
webView
:
(
WKWebView
*
)
webView
runJavaScriptAlertPanelWithMessage
:
(
NSString
*
)
message
initiatedByFrame
:
(
WKFrameInfo
*
)
frame
completionHandler
:
(
void
(
^
)(
void
))
completionHandler
{
NSLog
(
@"%s"
,
__FUNCTION__
);
UIAlertController
*
alert
=
[
UIAlertController
alertControllerWithTitle
:
@"alert"
message
:
@"JS调用alert"
preferredStyle
:
UIAlertControllerStyleAlert
];
UIAlertController
*
alert
=
[
UIAlertController
alertControllerWithTitle
:
@"alert"
message
:
@"JS调用alert"
preferredStyle
:
UIAlertControllerStyleAlert
];
[
alert
addAction
:[
UIAlertAction
actionWithTitle
:
@"确定"
style
:
UIAlertActionStyleDefault
handler
:
^
(
UIAlertAction
*
_Nonnull
action
)
{
[
alert
addAction
:[
UIAlertAction
actionWithTitle
:
@"确定"
style
:
UIAlertActionStyleDefault
handler
:
^
(
UIAlertAction
*
_Nonnull
action
)
{
completionHandler
();
completionHandler
();
}]];
}]];
[
self
presentViewController
:
alert
animated
:
YES
completion
:
NULL
];
[
self
presentViewController
:
alert
animated
:
YES
completion
:
NULL
];
N
SLog
(
@"message:%@"
,
message
);
D
SLog
(
@"message:%@"
,
message
);
}
}
#pragma mark - lazy
-
(
WKWebView
*
)
aiWebView
{
-
(
WKWebView
*
)
aiWebView
{
if
(
!
_aiWebView
)
{
if
(
!
_aiWebView
)
{
// 进行配置控制器
// 进行配置控制器
...
@@ -160,9 +157,6 @@
...
@@ -160,9 +157,6 @@
// 调用JS方法
// 调用JS方法
[
configuration
.
userContentController
addScriptMessageHandler
:
self
name
:
@"AppModel"
];
[
configuration
.
userContentController
addScriptMessageHandler
:
self
name
:
@"AppModel"
];
WKUserScript
*
reloadScript
=
[[
WKUserScript
alloc
]
initWithSource
:
@"window.addEventListener('pageshow', function(event){if(event.persisted){location.reload();}});"
injectionTime
:
WKUserScriptInjectionTimeAtDocumentEnd
forMainFrameOnly
:
YES
];
[
configuration
.
userContentController
addUserScript
:
reloadScript
];
// 进行偏好设置
// 进行偏好设置
WKPreferences
*
preferences
=
[
WKPreferences
new
];
WKPreferences
*
preferences
=
[
WKPreferences
new
];
preferences
.
javaScriptCanOpenWindowsAutomatically
=
YES
;
preferences
.
javaScriptCanOpenWindowsAutomatically
=
YES
;
...
@@ -170,9 +164,10 @@
...
@@ -170,9 +164,10 @@
configuration
.
preferences
=
preferences
;
configuration
.
preferences
=
preferences
;
// 初始化WKWebView
// 初始化WKWebView
_aiWebView
=
[[
WKWebView
alloc
]
initWithFrame
:
CGRectMake
(
0
,
4
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
.
UIDelegate
=
self
;
_aiWebView
.
hidden
=
YES
;
[
_aiWebView
debugViewShowBorder
];
[
_aiWebView
debugViewShowBorder
];
_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,4 +192,17 @@
...
@@ -197,4 +192,17 @@
return
_progressView
;
return
_progressView
;
}
}
-
(
ExceptionDefaultView
*
)
exceptionView
{
if
(
!
_exceptionView
)
{
WS
(
weakSelf
);
_exceptionView
=
[[
ExceptionDefaultView
alloc
]
initWithType
:
ExceptionTypeNet
block
:
^
{
weakSelf
.
progressView
.
hidden
=
NO
;
weakSelf
.
progressView
.
progress
=
0
;
weakSelf
.
exceptionView
.
hidden
=
YES
;
[
weakSelf
.
aiWebView
loadRequest
:
self
.
request
];
}
superView
:
self
.
view
];
}
return
_exceptionView
;
}
@end
@end
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论