cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

MDK Webview extension issue with JavaScript alerts for iOS MDK 2405

crayabharam
Explorer
0 Likes
240

Hello Experts,

I have created an extension of MDK 2405. I am using iOS native WKWebview, in the extension.

Earlier version of MDK SDK Version: 2105. This nativescript version was using TNS-CORE-MODULES.

The latest version of MDK 2405.* is based on Nativescript Version 8.6.5. TNS-CORE-MODULES is deprecated and using @nativescript/core.

iOS native WKWebview with custom WKWebView is working fine with TNS-CORE-MODULES.

WKWebView overridden methods are not getting triggered with the MDK 2405.* which is based on @nativescript/core.

Please suggest how to use this WKWebView with the latest version of MDK 2405* .

We are unable to get a callback from JS 

Below is the code snippet for iOS Native WebView in my extension working fine for MDK Version 2405* 

const messageHandler = FormMessageHandler.initWithOwner(this);
let wkcontent = WKUserContentController.new();
wkcontent.addScriptMessageHandlerName(messageHandler, "nativeProcess");
let webConfig = WKWebViewConfiguration.new();
webConfig.userContentController = wkcontent;
this._webView = WKWebView.new().initWithFrameConfiguration(CGRectMake(0, 0, 100, 600), webConfig);
this._webView.navigationDelegate = this.wkNavigationDelegate;
this._layout.addArrangedSubview(this._webView);

 

 
export class FormMessageHandler extends NSObject implements WKScriptMessageHandler {
public static ObjCProtocols = [WKScriptMessageHandler];
public contextField;
private owner: MySlider;
public static initWithOwner(owner: MySlider): FormMessageHandler {
const delegate = <FormMessageHandler>FormMessageHandler.new();
delegate.owner = owner;
return delegate;
}

public userContentControllerDidReceiveScriptMessage(userContentController: WKUserContentController, webViewMessage: WKScriptMessage) {
console.log("Reached");
console.log(webViewMessage.body);
let isFrom = webViewMessage.body.objectForKey("isfrom");
if (isFrom == "formSave" || isFrom == "formDraft") {
let hexaString = this.stringToHex(webViewMessage.body.objectForKey("filledform"));
var saveasString = "false";
if (isFrom == "formDraft") {
saveasString = "true"
}
this.owner.postForm(hexaString, saveasString);
}

else if (isFrom == "formAttach") {
// Service call for posting signature
var saveasString = "false";
if (isFrom == "formDraft") {
saveasString = "true"
}
this.owner.attachmentData = webViewMessage.body;
this.owner.appendAttachments(webViewMessage.body);
}
}
stringToHex(str) {
var result = '';
for (var i = 0; i < str.length; i++) {
result += str.charCodeAt(i).toString(16);
}
return result;
}
}

export class WKNavigationDelegateNotaImpl extends NSObject implements WKNavigationDelegate {
public static ObjCProtocols = [WKNavigationDelegate];

private owner: MySlider;
// const handlerClass = new MySlider();


// public handlerClass = MySlider.init1();

public static initWithOwner(owner: MySlider): WKNavigationDelegateNotaImpl {
const delegate = <WKNavigationDelegateNotaImpl>WKNavigationDelegateNotaImpl.new();
delegate.owner = owner;
return delegate;
}

public webViewDidFinishNavigation(webView: WKWebView, navigation: WKNavigation) {

console.log("Load Finished");
this.owner.webViewloadFinished();

}

}

 

Accepted Solutions (0)

Answers (0)