I am trying to call functions in android and iOS Swift(WKWebview)from javascript.
For Android:
public class WebAppInterface {
WebAppInterface(Context c) {
mContext = c;
}
@JavascriptInterface
public void postMessage(String message) {
Log.v(TAG, "message ----"+message);
Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show();
}
}
webView.addJavascriptInterface(new WebAppInterface(mContext), "appInterface");
JavaScript call For Android:
window.appInterface.postMessage("Hello);
Javascript call for iOS:
window.webkit.messageHandlers.appInterafce.postMeesage("Hello");
So, here we are making different calls from javascript for android and iOS.
Is it possible to call functions in both android and iOS in one single way?
Thanks.