I want to pass JSON data to javascript function related to web view. But I am unable to get the response data from the Javascript function I want to pass JSON data to javascript function related to web view. But I am unable to get the response data from the Javascript function json json

I want to pass JSON data to javascript function related to web view. But I am unable to get the response data from the Javascript function


Objective-c

- (void)runJavaScriptCallback:(NSString *) jsonString {    NSString *exec_template = @"downloadComplete(\'%@\');";    NSString *exec = [NSString stringWithFormat:exec_template, jsonString];    [webView evaluateJavaScript:exec completionHandler:nil];}

Swift 4

func runJavaScriptCallback(jsonString: String) {    webView.evaluateJavaScript("downloadComplete(\(jsonString))") { result, error in        guard error == nil else {            print(error)            return        }    }}

Javascript

var downloadComplete = (bridgeMsg) => {  // escape newline character from iOS sdp  bridgeMsg = bridgeMsg.replace(/\r?\n|\r/g, '\\r\\n');  const msg = JSON.parse(bridgeMsg);  // do whatever you want with the parsed json object};