Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
陈高翔
/
DreamSleep-iOS
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit d488a623
由
ilCode
编写于
2022-05-24 23:43:06 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
新增wkwebview清除缓存接口
1 个父辈
412bb9ae
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
137 行增加
和
7 行删除
DreamSleep/DreamSleep/Basement/Category/WKWebView+Extras.h
DreamSleep/DreamSleep/Basement/Category/WKWebView+Extras.m
DreamSleep/DreamSleep/Class/AISleepModule/AISleepCoach.storyboard
DreamSleep/DreamSleep/Class/AISleepModule/AISleepCoachController.m
DreamSleep/DreamSleep/Basement/Category/WKWebView+Extras.h
0 → 100644
查看文件 @
d488a62
//
// WKWebView+Extras.h
// DreamSleep
//
// Created by Peppa on 2022/5/24.
//
#import <WebKit/WebKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface
WKWebView
(
Extras
)
// 清除全部缓存
+
(
void
)
deleteWebCache
;
// 自定义清除缓存
+
(
void
)
customDeleteWebCache
;
// ios9以前清除缓存
+
(
void
)
clearCacheInCurrentVersion
;
@end
NS_ASSUME_NONNULL_END
DreamSleep/DreamSleep/Basement/Category/WKWebView+Extras.m
0 → 100644
查看文件 @
d488a62
//
// WKWebView+Extras.m
// DreamSleep
//
// Created by Peppa on 2022/5/24.
//
#import "WKWebView+Extras.h"
@implementation
WKWebView
(
Extras
)
+
(
void
)
deleteWebCache
{
// allWebsiteDataTypes清除所有缓存
NSSet
*
websiteDataTypes
=
[
WKWebsiteDataStore
allWebsiteDataTypes
];
NSDate
*
dateFrom
=
[
NSDate
dateWithTimeIntervalSince1970
:
0
];
[[
WKWebsiteDataStore
defaultDataStore
]
removeDataOfTypes
:
websiteDataTypes
modifiedSince
:
dateFrom
completionHandler
:^
{
}];
}
+
(
void
)
customDeleteWebCache
{
/*
在磁盘缓存上。
WKWebsiteDataTypeDiskCache,
html离线Web应用程序缓存。
WKWebsiteDataTypeOfflineWebApplicationCache,
内存缓存。
WKWebsiteDataTypeMemoryCache,
本地存储。
WKWebsiteDataTypeLocalStorage,
Cookies
WKWebsiteDataTypeCookies,
会话存储
WKWebsiteDataTypeSessionStorage,
IndexedDB数据库。
WKWebsiteDataTypeIndexedDBDatabases,
查询数据库。
WKWebsiteDataTypeWebSQLDatabases
*/
NSArray
*
types
=
@[
WKWebsiteDataTypeCookies
,
WKWebsiteDataTypeLocalStorage
,
WKWebsiteDataTypeDiskCache
,
WKWebsiteDataTypeMemoryCache
,
WKWebsiteDataTypeOfflineWebApplicationCache
];
NSSet
*
websiteDataTypes
=
[
NSSet
setWithArray
:
types
];
NSDate
*
dateFrom
=
[
NSDate
dateWithTimeIntervalSince1970
:
0
];
[[
WKWebsiteDataStore
defaultDataStore
]
removeDataOfTypes
:
websiteDataTypes
modifiedSince
:
dateFrom
completionHandler
:^
{
}];
}
+
(
void
)
clearCacheInCurrentVersion
{
}
@end
DreamSleep/DreamSleep/Class/AISleepModule/AISleepCoach.storyboard
查看文件 @
d488a62
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<document
type=
"com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB"
version=
"3.0"
toolsVersion=
"20037"
targetRuntime=
"iOS.CocoaTouch"
propertyAccessControl=
"none"
useAutolayout=
"YES"
useTraitCollections=
"YES"
useSafeAreas=
"YES"
colorMatched=
"YES"
initialViewController=
"
dDK-KA-sPQ
"
>
<document
type=
"com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB"
version=
"3.0"
toolsVersion=
"20037"
targetRuntime=
"iOS.CocoaTouch"
propertyAccessControl=
"none"
useAutolayout=
"YES"
useTraitCollections=
"YES"
useSafeAreas=
"YES"
colorMatched=
"YES"
initialViewController=
"
JOD-MV-Pim
"
>
<device
id=
"retina6_1"
orientation=
"portrait"
appearance=
"light"
/>
<device
id=
"retina6_1"
orientation=
"portrait"
appearance=
"light"
/>
<dependencies>
<dependencies>
<deployment
identifier=
"iOS"
/>
<deployment
identifier=
"iOS"
/>
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
<capability
name=
"documents saved in the Xcode 8 format"
minToolsVersion=
"8.0"
/>
<capability
name=
"documents saved in the Xcode 8 format"
minToolsVersion=
"8.0"
/>
</dependencies>
</dependencies>
<scenes>
<scenes>
<!--
AI睡眠教练
-->
<!--
Sleep Coach Controller
-->
<scene
sceneID=
"mSr-VG-EoP"
>
<scene
sceneID=
"mSr-VG-EoP"
>
<objects>
<objects>
<viewController
id=
"dDK-KA-sPQ"
customClass=
"AISleepCoachController"
sceneMemberID=
"viewController"
>
<viewController
id=
"dDK-KA-sPQ"
customClass=
"AISleepCoachController"
sceneMemberID=
"viewController"
>
...
@@ -19,11 +19,30 @@
...
@@ -19,11 +19,30 @@
<viewLayoutGuide
key=
"safeArea"
id=
"Pf1-fh-l6V"
/>
<viewLayoutGuide
key=
"safeArea"
id=
"Pf1-fh-l6V"
/>
<color
key=
"backgroundColor"
systemColor=
"systemBackgroundColor"
/>
<color
key=
"backgroundColor"
systemColor=
"systemBackgroundColor"
/>
</view>
</view>
<
tabBarItem
key=
"tabBarItem"
title=
"AI睡眠教练"
image=
"aisleep"
selectedImage=
"aisleep_selected"
id=
"Il3-d5-iMT
"
/>
<
navigationItem
key=
"navigationItem"
id=
"05K-ik-z2W
"
/>
</viewController>
</viewController>
<placeholder
placeholderIdentifier=
"IBFirstResponder"
id=
"8JB-OR-j2U"
userLabel=
"First Responder"
customClass=
"UIResponder"
sceneMemberID=
"firstResponder"
/>
<placeholder
placeholderIdentifier=
"IBFirstResponder"
id=
"8JB-OR-j2U"
userLabel=
"First Responder"
customClass=
"UIResponder"
sceneMemberID=
"firstResponder"
/>
</objects>
</objects>
<point
key=
"canvasLocation"
x=
"2022"
y=
"201"
/>
<point
key=
"canvasLocation"
x=
"2786"
y=
"201"
/>
</scene>
<!--AI睡眠教练-->
<scene
sceneID=
"zZV-8x-0UY"
>
<objects>
<navigationController
automaticallyAdjustsScrollViewInsets=
"NO"
id=
"JOD-MV-Pim"
customClass=
"BaseNaviController"
sceneMemberID=
"viewController"
>
<tabBarItem
key=
"tabBarItem"
title=
"AI睡眠教练"
image=
"aisleep"
selectedImage=
"aisleep_selected"
id=
"Il3-d5-iMT"
/>
<toolbarItems/>
<navigationBar
key=
"navigationBar"
contentMode=
"scaleToFill"
id=
"IbM-gj-oZu"
>
<rect
key=
"frame"
x=
"0.0"
y=
"44"
width=
"414"
height=
"44"
/>
<autoresizingMask
key=
"autoresizingMask"
/>
</navigationBar>
<nil
name=
"viewControllers"
/>
<connections>
<segue
destination=
"dDK-KA-sPQ"
kind=
"relationship"
relationship=
"rootViewController"
id=
"ACD-cx-BP7"
/>
</connections>
</navigationController>
<placeholder
placeholderIdentifier=
"IBFirstResponder"
id=
"hMf-jH-a0Q"
userLabel=
"First Responder"
customClass=
"UIResponder"
sceneMemberID=
"firstResponder"
/>
</objects>
<point
key=
"canvasLocation"
x=
"2021.7391304347827"
y=
"200.89285714285714"
/>
</scene>
</scene>
</scenes>
</scenes>
<resources>
<resources>
...
...
DreamSleep/DreamSleep/Class/AISleepModule/AISleepCoachController.m
查看文件 @
d488a62
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
#import "AISleepCoachController.h"
#import "AISleepCoachController.h"
#import <WebKit/WebKit.h>
#import <WebKit/WebKit.h>
#import <JavaScriptCore/JavaScriptCore.h>
#import <JavaScriptCore/JavaScriptCore.h>
#import "WKWebView+Extras.h"
@interface
AISleepCoachController
()
<
WKNavigationDelegate
,
WKScriptMessageHandler
,
WKUIDelegate
>
@interface
AISleepCoachController
()
<
WKNavigationDelegate
,
WKScriptMessageHandler
,
WKUIDelegate
>
@property
(
strong
,
nonatomic
)
WKWebView
*
aiWebView
;
@property
(
strong
,
nonatomic
)
WKWebView
*
aiWebView
;
...
@@ -33,6 +34,16 @@
...
@@ -33,6 +34,16 @@
[[
NSNotificationCenter
defaultCenter
]
removeObserver
:
self
name
:
NeedUpdateAICoach
object
:
nil
];
[[
NSNotificationCenter
defaultCenter
]
removeObserver
:
self
name
:
NeedUpdateAICoach
object
:
nil
];
}
}
#pragma mark - 关闭侧滑
-
(
BOOL
)
enableInteractivePopGestureRecognizer
{
return
NO
;
}
#pragma mark - 隐藏导航栏
-
(
BOOL
)
isShowNavigationBar
{
return
YES
;
}
-
(
void
)
viewWillAppear
:
(
BOOL
)
animated
{
-
(
void
)
viewWillAppear
:
(
BOOL
)
animated
{
[
super
viewWillAppear
:
animated
];
[
super
viewWillAppear
:
animated
];
...
@@ -51,9 +62,14 @@
...
@@ -51,9 +62,14 @@
}
}
}
}
-
(
void
)
touchesBegan
:
(
NSSet
<
UITouch
*>
*
)
touches
withEvent
:
(
UIEvent
*
)
event
{
[
self
.
aiWebView
reload
];
}
#pragma mark - 登录成功后刷新
#pragma mark - 登录成功后刷新
-
(
void
)
needUpdateAiCoach
{
-
(
void
)
needUpdateAiCoach
{
[
self
.
aiWebView
loadRequest
:
self
.
request
];
[
WKWebView
deleteWebCache
];
[
self
.
aiWebView
reload
];
}
}
#pragma mark - WKWebView的监听方法
#pragma mark - WKWebView的监听方法
...
@@ -97,8 +113,14 @@
...
@@ -97,8 +113,14 @@
if
([
message
.
name
isEqualToString
:
@"AppModel"
])
{
if
([
message
.
name
isEqualToString
:
@"AppModel"
])
{
// 打印所传过来的参数,只支持NSNumber, NSString, NSDate, NSArray,
// 打印所传过来的参数,只支持NSNumber, NSString, NSDate, NSArray,
// NSDictionary, and NSNull类型
// NSDictionary, and NSNull类型
NSDictionary
*
bodyDic
=
message
.
body
;
NSDictionary
*
bodyDic
=
message
.
body
;
NSLog
(
@"message.body:%@, type:%d"
,
bodyDic
,
[
bodyDic
[
@"type"
]
intValue
]);
DSLog
(
@"message.body:%@, type:%d"
,
bodyDic
,
[
bodyDic
[
@"type"
]
intValue
]);
int
type
=
[
bodyDic
[
@"type"
]
intValue
];
if
(
type
==
1
)
{
// 未登录点击开启
[
self
startOpen
];
}
}
}
// if ([message.name isEqualToString:@"xxx"]) {
// if ([message.name isEqualToString:@"xxx"]) {
...
@@ -138,6 +160,9 @@
...
@@ -138,6 +160,9 @@
// 调用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
;
...
@@ -145,7 +170,7 @@
...
@@ -145,7 +170,7 @@
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
,
4
0
,
kScreenWidth
,
kScreenHeight
-
kTabBarHeight
)
configuration
:
configuration
];
_aiWebView
.
backgroundColor
=
DSWhite
;
_aiWebView
.
backgroundColor
=
DSWhite
;
_aiWebView
.
UIDelegate
=
self
;
_aiWebView
.
UIDelegate
=
self
;
[
_aiWebView
debugViewShowBorder
];
[
_aiWebView
debugViewShowBorder
];
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论