From 937a32e948a1a6997e964fbc3c3f2d17cffd7a91 Mon Sep 17 00:00:00 2001 From: Alex Fung Date: Wed, 27 May 2020 19:45:50 +1200 Subject: [PATCH] add initWithCoder and commonInit --- dsbridge/DWKWebView.m | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/dsbridge/DWKWebView.m b/dsbridge/DWKWebView.m index 1bfbbff..2e54d3c 100644 --- a/dsbridge/DWKWebView.m +++ b/dsbridge/DWKWebView.m @@ -24,9 +24,26 @@ @implementation DWKWebView bool isDebug; } +-(instancetype)initWithCoder:(NSCoder *)coder +{ + self = [super initWithCoder:coder]; + if (self) { + [self commonInit]; + } + return self; +} -(instancetype)initWithFrame:(CGRect)frame configuration:(WKWebViewConfiguration *)configuration { + self = [super initWithFrame:frame configuration: configuration]; + if (self) { + [self commonInit]; + } + return self; +} + +-(void)commonInit{ + super.UIDelegate=self; txtName=nil; dialogType=0; callId=0; @@ -46,16 +63,12 @@ -(instancetype)initWithFrame:(CGRect)frame configuration:(WKWebViewConfiguration WKUserScript *script = [[WKUserScript alloc] initWithSource:@"window._dswk=true;" injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:YES]; - [configuration.userContentController addUserScript:script]; - self = [super initWithFrame:frame configuration: configuration]; - if (self) { - super.UIDelegate=self; - } + [self.configuration.userContentController addUserScript:script]; + // add internal Javascript Object InternalApis * interalApis= [[InternalApis alloc] init]; interalApis.webview=self; [self addJavascriptObject:interalApis namespace:@"_dsb"]; - return self; } - (void)webView:(WKWebView *)webView runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt