How to send events from HTML running inside a UIWebView to native Objective-C code?

前端 未结 4 1559
暖寄归人
暖寄归人 2021-02-04 14:44

I want to integrate a full HTML framework (ie HTML/CSS/JavaScript) inside an iOS app and make the UIWebView in charge of running the HTML content being able to communicate with

4条回答
  •  广开言路
    2021-02-04 15:25

    The way you usually talk back from JavaScript is by opening a fictional URL (by window.location), and then implementing UIWebViewDelegate's -webView:shouldStartLoadWithRequest:navigationType: to ignore the navigation and handle what needs to be done instead.

    (On Mac OS X WebKit, you can supply Objective-C objects that have JavaScript functions to the web site, but this is not available in iOS.)

提交回复
热议问题