Skip to content

Commit db8e7a5

Browse files
committed
1.2.1
support clear caches
1 parent 8128671 commit db8e7a5

File tree

4 files changed

+33
-6
lines changed

4 files changed

+33
-6
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ source 'https://github.com/CocoaPods/Specs.git'
2020
platform :ios, '9.0'
2121
2222
target 'TargetName' do
23-
pod 'ZFWKWebView', '~> 1.2.0'
23+
pod 'ZFWKWebView', '~> 1.2.1'
2424
end
2525
```
2626
Then, run the following command:

ZFWKWebView.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
Pod::Spec.new do |s|
1111
s.name = "ZFWKWebView"
12-
s.version = "1.2.0"
12+
s.version = "1.2.1"
1313
s.summary = "No short description of ZFWKWebView."
1414
s.homepage = "https://github.com/FranLucky/ZFWKWebView"
1515
s.license = { :type => "MIT", :file => "LICENSE"}

ZFWKWebView/ZFWKWebVC.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ UIKIT_EXTERN ZFWKWebViewEventKey const ZFWKWebViewEventViewDidDisappear;
4141
UIKIT_EXTERN ZFWKWebViewEventKey const ZFWKWebViewEventViewDidLoad;
4242
UIKIT_EXTERN ZFWKWebViewEventKey const ZFWKWebViewEventViewWillLayoutSubviews;
4343

44+
45+
4446
@interface ZFWKWebVCConf : NSObject
4547
/**
4648
* ZFWKWebVCPopTypePervious => popViewControllerAnimated (default)
@@ -99,8 +101,6 @@ UIKIT_EXTERN ZFWKWebViewEventKey const ZFWKWebViewEventViewWillLayoutSubviews;
99101

100102

101103

102-
103-
104104
@interface ZFWKWebVC : UIViewController
105105
- (instancetype)initWithDefaultConfig;
106106
- (instancetype)initWithConf:(ZFWKWebVCConf *)conf;
@@ -109,6 +109,9 @@ UIKIT_EXTERN ZFWKWebViewEventKey const ZFWKWebViewEventViewWillLayoutSubviews;
109109
- (void)removeUserScript:(NSString *)script;
110110
- (void)reloadPreviousRequest;
111111

112+
- (void)clearAllCaches API_AVAILABLE(ios(9.0));
113+
- (void)clearCachesWithSet:(NSSet *)cacheSet API_AVAILABLE(ios(9.0));
114+
112115
@property (nonatomic, strong, readonly) WKWebView *webView;
113116
@property (nonatomic, strong, nullable) ZFWKWebVCBottomBar *bottomBar;
114117
@property (nonatomic, strong, readonly) ZFWKWebVCConf *config;

ZFWKWebView/ZFWKWebVC.m

+26-2
Original file line numberDiff line numberDiff line change
@@ -750,10 +750,34 @@ - (void)userContentController:(WKUserContentController *)userContentController d
750750
callback(self, self.config, message.body);
751751
}
752752
}
753-
754-
755753
}
756754

755+
- (void)clearAllCaches {
756+
if (@available(iOS 9.0, *)) {
757+
NSSet *cacheTypes = [NSSet setWithArray:@[
758+
WKWebsiteDataTypeMemoryCache,
759+
WKWebsiteDataTypeSessionStorage,
760+
WKWebsiteDataTypeDiskCache,
761+
WKWebsiteDataTypeOfflineWebApplicationCache,
762+
WKWebsiteDataTypeCookies,
763+
WKWebsiteDataTypeLocalStorage,
764+
WKWebsiteDataTypeIndexedDBDatabases,
765+
WKWebsiteDataTypeWebSQLDatabases,
766+
]];
767+
[self clearCachesWithSet:cacheTypes];
768+
} else {
769+
NSLog(@"API %s support @available(iOS 9.0, *)", __func__);
770+
}
771+
}
757772

773+
- (void)clearCachesWithSet:(NSSet *)cacheSet {
774+
if (@available(iOS 9.0, *)) {
775+
[[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:cacheSet
776+
modifiedSince:[NSDate dateWithTimeIntervalSince1970:0]
777+
completionHandler:^{}];
778+
} else {
779+
NSLog(@"API %s support @available(iOS 9.0, *)", __func__);
780+
}
781+
}
758782

759783
@end

0 commit comments

Comments
 (0)