Эх сурвалжийг харах

Migrate to WKWebView

Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
Lukas Reschke 8 жил өмнө
parent
commit
d5389a7b98

+ 2 - 1
iOSClient/Main/CCDetail.h

@@ -23,6 +23,7 @@
 
 #import <UIKit/UIKit.h>
 #import <Foundation/Foundation.h>
+#import <WebKit/WebKit.h>
 
 #import "UIImage+animatedGIF.h"
 #import "LMMediaPlayerView.h"
@@ -46,7 +47,7 @@
 @property (nonatomic, strong) NSDate *dateFilterQuery;
 
 // Document
-@property (nonatomic, strong) UIWebView *webView;
+@property (nonatomic, strong) WKWebView *webView;
 
 // Photo-Video
 @property (nonatomic, strong) NSMutableArray *dataSourceImagesVideos;

+ 7 - 6
iOSClient/Main/CCDetail.m

@@ -137,7 +137,6 @@
     if (_webView) {
             
         [_webView removeFromSuperview];
-        _webView.delegate = nil;
         _webView = nil;
     }
         
@@ -312,7 +311,12 @@
     NSString *ext=@"";
     ext = [CCUtility getExtension:self.metadataDetail.fileNamePrint];
     
-    self.webView = [[UIWebView alloc] initWithFrame:(CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT))];
+    WKPreferences *wkPreferences = [[WKPreferences alloc] init];
+    wkPreferences.javaScriptEnabled = false;
+    WKWebViewConfiguration *wkConfig = [[WKWebViewConfiguration alloc] init];
+    wkConfig.preferences = wkPreferences;
+
+    self.webView = [[WKWebView alloc] initWithFrame:(CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT)) configuration:wkConfig];
     self.webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
 
     [self.webView setBackgroundColor:[UIColor whiteColor]];
@@ -348,16 +352,13 @@
         if (error != nil) {
             NSLog(@"[LOG] loadURLWithString %@",[error localizedDescription]);
         }
-        NSString *mimeType = [headResponse MIMEType];
-        
-        [self.webView loadData:[NSData dataWithContentsOfURL: [NSURL fileURLWithPath:fileName]] MIMEType:mimeType textEncodingName:@"utf-8" baseURL:[NSURL URLWithString:@""]];
         
+        [self.webView loadRequest:[NSMutableURLRequest requestWithURL:[NSURL fileURLWithPath:fileName]]];
     } else {
         
         [self.webView loadRequest:[NSMutableURLRequest requestWithURL:[NSURL fileURLWithPath:fileName]]];
     }
     
-    [self.webView setScalesPageToFit:YES];
     [self.view addSubview:self.webView];
 }