|
@@ -361,6 +361,7 @@ NSString *const new_AesKey_1 = @"mGlAgnIBB8bx2nch";
|
|
|
// 在发送请求之前,决定是否跳转
|
|
|
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
|
|
|
// 获取完整url并进行UTF-8转码
|
|
|
+
|
|
|
NSString *strRequest = [navigationAction.request.URL.absoluteString stringByRemovingPercentEncoding];
|
|
|
if ([strRequest containsString:@"jyapp/article/content"]) {
|
|
|
NSLog(@"拦截的链接:%@",strRequest);
|
|
@@ -470,7 +471,6 @@ NSString *const new_AesKey_1 = @"mGlAgnIBB8bx2nch";
|
|
|
}
|
|
|
|
|
|
-(void)bottomOneListening {
|
|
|
- NSLog(@"tab-search");
|
|
|
if(self.tabBarController.selectedIndex == 0) {
|
|
|
[self judgeIsHiddenBottom];
|
|
|
}
|
|
@@ -606,11 +606,28 @@ NSString *const new_AesKey_1 = @"mGlAgnIBB8bx2nch";
|
|
|
if(!notiFinish) {
|
|
|
notiFinish = YES;
|
|
|
}
|
|
|
+
|
|
|
[self judgeIsHiddenBottom];//是否隐藏
|
|
|
[self removeNoNetViews];
|
|
|
[[LXViewControllerManager shareViewControllerManager] hideHud];
|
|
|
+ //写数据
|
|
|
+// [self writeWKWebData:webView.URL];
|
|
|
+}
|
|
|
+
|
|
|
+-(void)writeWKWebData:(NSURL *)url {
|
|
|
+ //得到NSData 数据
|
|
|
+ NSData *dataContent = [NSData dataWithContentsOfURL:url];
|
|
|
+ //NSURLCache 实例化
|
|
|
+ NSURLCache *cache = [NSURLCache sharedURLCache];
|
|
|
+ //得到相应
|
|
|
+ NSURLResponse *response = [[NSURLResponse alloc]initWithURL:url MIMEType:nil expectedContentLength:0 textEncodingName:@"UTF-8"];
|
|
|
+ //得到CacheURLResponse
|
|
|
+ NSCachedURLResponse *cacheResponse = [[NSCachedURLResponse alloc]initWithResponse:response data:dataContent];
|
|
|
+ //进行存储
|
|
|
+ [cache storeCachedResponse:cacheResponse forRequest:[NSURLRequest requestWithURL:url]];
|
|
|
}
|
|
|
|
|
|
+
|
|
|
// 页面开始加载时调用
|
|
|
- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation{
|
|
|
|
|
@@ -628,7 +645,6 @@ NSString *const new_AesKey_1 = @"mGlAgnIBB8bx2nch";
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
#pragma mark *****JS与OC交互
|
|
|
#pragma mark - WKScriptMessageHandler JS调OC交互
|
|
|
-(void)jsLoginByWeixin:(NSDictionary *)dict {
|
|
@@ -1552,6 +1568,49 @@ NSString *const new_AesKey_1 = @"mGlAgnIBB8bx2nch";
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+- (void)clearCache {
|
|
|
+ /* 取得Library文件夹的位置*/
|
|
|
+ NSString *libraryDir = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,NSUserDomainMask, YES)[0];
|
|
|
+ /* 取得bundle id,用作文件拼接用*/
|
|
|
+ NSString *bundleId = [[[NSBundle mainBundle] infoDictionary]objectForKey:@"CFBundleIdentifier"];
|
|
|
+ /*
|
|
|
+ * 拼接缓存地址,具体目录为App/Library/Caches/你的APPBundleID/fsCachedData
|
|
|
+ */
|
|
|
+ NSString *webKitFolderInCachesfs = [NSString stringWithFormat:@"%@/Caches/%@/fsCachedData",libraryDir,bundleId];
|
|
|
+
|
|
|
+ NSError *error;
|
|
|
+ /* 取得目录下所有的文件,取得文件数组*/
|
|
|
+ NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
|
+// NSArray *fileList = [[NSArray alloc] init];
|
|
|
+ //fileList便是包含有该文件夹下所有文件的文件名及文件夹名的数组
|
|
|
+ NSArray *fileList = [fileManager contentsOfDirectoryAtPath:webKitFolderInCachesfs error:&error];
|
|
|
+ /* 遍历文件组成的数组*/
|
|
|
+ for(NSString * fileName in fileList){
|
|
|
+ /* 定位每个文件的位置*/
|
|
|
+ NSString * path = [[NSBundle bundleWithPath:webKitFolderInCachesfs] pathForResource:fileName ofType:@""];
|
|
|
+ /* 将文件转换为NSData类型的数据*/
|
|
|
+ NSData * fileData = [NSData dataWithContentsOfFile:path];
|
|
|
+ /* 如果FileData的长度大于2,说明FileData不为空*/
|
|
|
+ if(fileData.length >2){
|
|
|
+ /* 创建两个用于显示文件类型的变量*/
|
|
|
+ int char1 =0;
|
|
|
+ int char2 =0;
|
|
|
+
|
|
|
+ [fileData getBytes:&char1 range:NSMakeRange(0,1)];
|
|
|
+ [fileData getBytes:&char2 range:NSMakeRange(1,1)];
|
|
|
+ /* 拼接两个变量*/
|
|
|
+ NSString *numStr = [NSString stringWithFormat:@"%i%i",char1,char2];
|
|
|
+ /* 如果该文件前四个字符是6033,说明是Html文件,删除掉本地的缓存*/
|
|
|
+ if([numStr isEqualToString:@"6033"]){
|
|
|
+ [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@",webKitFolderInCachesfs,fileName]error:&error];
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
/*
|
|
|
#pragma mark - Navigation
|
|
|
|