Interaction between oc and js ----- WKWebView, oc ----- wkwebview

Source: Internet
Author: User

Interaction between oc and js ----- WKWebView, oc ----- wkwebview

I have studied the interaction between oc and js over the past few days.

Interaction between oc and js is a cross-platform communication between iOS and javaScript. To reduce development costs, the company developed Android and iOS apps, by loading javaScript through webView, you only need to do some interactive work, so that pages written in javaScript can be used simultaneously on Android and iOS.

Methods In WKWebView

1. Call js methods in OC (I think oc transmits values to js)

Yes

<Span style = "background-color: rgb (255,255,255);">-(void) evaluateJavaScript :( NSString *) javaScriptString completionHandler :( void (^) (id, NSError *)) completionHandler; this method </span>

Parameter 1: @ param is the js method called and the value is passed.

Parameter 2: IfJavaScriptCode error.CompletionHandlerProcessing.


2. WKWebView registers the WKScriptMessageHandler agent when js transmits values to oc.

-(

-(Void) userContentController :( WKUserContentController *) userContentController didReceiveScriptMessage :( WKScriptMessage *) message; <span style = "color: # ffffff;"> </span>

Parameter 2: Information transmitted by js to oc




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.