In WKWebView we can call ObjectiveC/swift code using webkit message handlers
eg: webkit.messageHandlers.
It works we
I have a workaround for question1.
PostMessage with JavaScript
window.webkit.messageHandlers..postMessage(function(data){alert(data);}+"");
Handle It in your Objective-C project
-(void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message{
NSString *callBackString = message.body;
callBackString = [@"(" stringByAppendingString:callBackString];
callBackString = [callBackString stringByAppendingFormat:@")('%@');", @"Some RetString"];
[message.webView evaluateJavaScript:callBackString completionHandler:^(id _Nullable obj, NSError * _Nullable error) {
if (error) {
NSLog(@"name = %@ error = %@",@"", error.localizedDescription);
}
}];
}