Skip to content

Commit 937a32e

Browse files
committed
add initWithCoder and commonInit
1 parent f0e3c72 commit 937a32e

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

dsbridge/DWKWebView.m

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,26 @@ @implementation DWKWebView
2424
bool isDebug;
2525
}
2626

27+
-(instancetype)initWithCoder:(NSCoder *)coder
28+
{
29+
self = [super initWithCoder:coder];
30+
if (self) {
31+
[self commonInit];
32+
}
33+
return self;
34+
}
2735

2836
-(instancetype)initWithFrame:(CGRect)frame configuration:(WKWebViewConfiguration *)configuration
2937
{
38+
self = [super initWithFrame:frame configuration: configuration];
39+
if (self) {
40+
[self commonInit];
41+
}
42+
return self;
43+
}
44+
45+
-(void)commonInit{
46+
super.UIDelegate=self;
3047
txtName=nil;
3148
dialogType=0;
3249
callId=0;
@@ -46,16 +63,12 @@ -(instancetype)initWithFrame:(CGRect)frame configuration:(WKWebViewConfiguration
4663
WKUserScript *script = [[WKUserScript alloc] initWithSource:@"window._dswk=true;"
4764
injectionTime:WKUserScriptInjectionTimeAtDocumentStart
4865
forMainFrameOnly:YES];
49-
[configuration.userContentController addUserScript:script];
50-
self = [super initWithFrame:frame configuration: configuration];
51-
if (self) {
52-
super.UIDelegate=self;
53-
}
66+
[self.configuration.userContentController addUserScript:script];
67+
5468
// add internal Javascript Object
5569
InternalApis * interalApis= [[InternalApis alloc] init];
5670
interalApis.webview=self;
5771
[self addJavascriptObject:interalApis namespace:@"_dsb"];
58-
return self;
5972
}
6073

6174
- (void)webView:(WKWebView *)webView runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt

0 commit comments

Comments
 (0)