Forráskód Böngészése

设置 缓存空间

apple 5 éve
szülő
commit
769883e9e4

BIN
ios/JianYuIOS/JianYuIOS.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate


+ 16 - 6
ios/JianYuIOS/JianYuIOS/AppDelegate.m

@@ -21,6 +21,7 @@
 #import "ZKGuideView.h"
 #import "JYKeyCustom.h"
 #import "JYOldCustom.h"
+#import <WebKit/WebKit.h>
 @interface AppDelegate ()<JPUSHRegisterDelegate,WXApiDelegate,UNUserNotificationCenterDelegate>
 
 @property(nonatomic, strong)UIImageView *imgView;
@@ -42,9 +43,8 @@
     //    [self initOldKey];
     [self initJYBXKey];
     
-//    NSURLCache *URLCache = [[NSURLCache alloc] initWithMemoryCapacity:4 * 1024 * 1024 diskCapacity:20 * 1024 * 1024 diskPath:nil];
-//
-//    [NSURLCache setSharedURLCache:URLCache];
+    NSURLCache *URLCache = [[NSURLCache alloc] initWithMemoryCapacity:1000 * 1024 * 1024 diskCapacity:1000 * 1024 * 1024 diskPath:nil];
+    [NSURLCache setSharedURLCache:URLCache];
     
     NSString *isProvacy = [[NSUserDefaults standardUserDefaults] objectForKey:@"FirstPrivacy"];
     if ([isProvacy isEqualToString:@"1"]) {
@@ -61,7 +61,7 @@
     [LXDataBaseManager shareDataBaseManager];//初始化单例
     [LXViewControllerManager shareViewControllerManager];
     [self initJPush:launchOptions];
-//    [self initUM];
+    [self initUM];
     [self registeredPush]; //注册原生推送
 
     if (launchOptions) {
@@ -83,6 +83,17 @@
     
     return YES;
 }
+- (NSString *)encode:(NSString *)string
+{
+    //先将string转换成data
+    NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
+    
+    NSData *base64Data = [data base64EncodedDataWithOptions:0];
+    
+    NSString *baseString = [[NSString alloc]initWithData:base64Data encoding:NSUTF8StringEncoding];
+    
+    return baseString;
+}
 - (NSString *)decodeString:(NSString *)string
 {
     NSData *data = [[NSData alloc] initWithBase64EncodedString:string options:0];
@@ -96,9 +107,8 @@
 }
 
 -(void)initJYBXKey {
-
     [NSURLProtocol registerClass:[JYKeyCustom class]];
-    Class cls = NSClassFromString([self decodeString:@"V0tCcm93c2luZ0NvbnRleHRDb250cm9sbGVy"]);
+    Class cls = [[[WKWebView new] valueForKey:[self decodeString:@"YnJvd3NpbmdDb250ZXh0Q29udHJvbGxlcg=="]] class];
     SEL sel = NSSelectorFromString([self decodeString:@"cmVnaXN0ZXJTY2hlbWVGb3JDdXN0b21Qcm90b2NvbDo="]);
     if([(id)cls respondsToSelector:sel]) {
     #pragma clang diagnostic push

+ 16 - 5
ios/JianYuIOS/JianYuIOS/Classes(模块)/JYNewExpViewController.m

@@ -392,7 +392,6 @@ NSString *const new_AesKey_3 = @"mGlAgnIBB8bx2nch";
     [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(bottomThreeListening) userInfo:nil repeats:YES];
 }
 -(void)bottomThreeListening {
-    NSLog(@"tab-exp");
     if(self.tabBarController.selectedIndex == 2) {
         [self judgeIsHiddenBottom];
     }
@@ -407,12 +406,24 @@ NSString *const new_AesKey_3 = @"mGlAgnIBB8bx2nch";
     [self removeNoNetViews];
     [[LXViewControllerManager shareViewControllerManager] hideHud];
     
-//    [self performSelector:@selector(afterPageClick) withObject:nil afterDelay:2];
+
+    //写数据
+//    [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)afterPageClick {
-//    [self isExitCallToJS:@"afterPageInit()" withMethodName:@"afterPageInit"];
-//}
 // 页面开始加载时调用
 - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation{
     

+ 15 - 1
ios/JianYuIOS/JianYuIOS/Classes(模块)/JYNewMineViewController.m

@@ -417,7 +417,6 @@ NSString *const new_AesKey_4 = @"mGlAgnIBB8bx2nch";
 }
 
 -(void)bottomFourListening {
-    NSLog(@"tab-my");
     if(self.tabBarController.selectedIndex == 3) {
         [self judgeIsHiddenBottom];
     }
@@ -432,8 +431,23 @@ NSString *const new_AesKey_4 = @"mGlAgnIBB8bx2nch";
     [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:@"text/html" 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{
     

+ 61 - 2
ios/JianYuIOS/JianYuIOS/Classes(模块)/JYNewSearchViewController.m

@@ -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
 

+ 17 - 4
ios/JianYuIOS/JianYuIOS/Classes(模块)/JYNewSubViewController.m

@@ -400,7 +400,6 @@ NSString *const new_AesKey_2 = @"mGlAgnIBB8bx2nch";
     [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(bottomTwoListening) userInfo:nil repeats:YES];
 }
 -(void)bottomTwoListening {
-    NSLog(@"tab-sub");
     if(self.tabBarController.selectedIndex == 1) {
         [self judgeIsHiddenBottom];
     }
@@ -416,11 +415,25 @@ NSString *const new_AesKey_2 = @"mGlAgnIBB8bx2nch";
     [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:@"text/html" expectedContentLength:0 textEncodingName:@"UTF-8"];
+    //得到CacheURLResponse
+    NSCachedURLResponse *cacheResponse = [[NSCachedURLResponse alloc]initWithResponse:response data:dataContent];
+    //进行存储
+    [cache storeCachedResponse:cacheResponse forRequest:[NSURLRequest requestWithURL:url]];
 }
 
-//-(void)afterPageClick {
-//    [self isExitCallToJS:@"afterPageInit()" withMethodName:@"afterPageInit"];
-//}
 // 页面开始加载时调用
 - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation{