iOS: call obj-c methods using javascript in a UIWebview

前端 未结 3 472
你的背包
你的背包 2021-02-01 11:12

I am writing a function that collaborates with a JS web page. I use UIWebView to contain the webpage and then situation has become complicated when I want the web page to commun

3条回答
  •  执笔经年
    2021-02-01 11:52

    I guess using delegate is the only (one or two) methodology you can use in iOS WebView. But there are several wrappers that may help you easy out.

    1. EasyJSWebView - This replicates the development experience as in Android. In Android, you can simply use the addJavascriptInterface() method in WebView to bridge the Javascript to Java. EasyJSWebView provides both sync-style and async-style for getting the return value from Objective-C methods.

    2. WebViewJavascriptBridge - The code may look a little bit like socket programming. You can pass data to and fro between the "server" in Objective-C and the "client" in Javascript.

    3. GAJavaScript - This may provide a better DOM manipulation experience.

    Take a look at all of them and choose one that fits your need.

提交回复
热议问题