Oc-->js Stringbyevaluatingjavascriptfromstring, whose argument is a nsstring string content is the JS code (this can be a JS function, a JS code or their combination), When the JS function has a return value or a sentence JS code has a value returned can be obtained by stringbyevaluatingjavascriptfromstring return value.
Js-->oc Using the WebView redirection principle (that is, to re-specify the value of Document.location in JS, this is a URL), as long as the custom rules in this URL string to specify the required functions and parameters in OC, and then through the OC in the Shouldstartloadwithreque The St function goes to capture processing requests.
App calls WebView loaded JS method Interfacecalledbyapp, this example passed two parameters-(void) SendMessage: (ID) Sender { [Self.webview Stringbyevaluatingjavascriptfromstring:[nsstring stringwithformat:@ "Interfacecalledbyapp (\"%@\ ", \"%@\ ")", @ "2", @ "333"];}
JS to the app to pass the value. First implement the UIWebView agent, and then according to the Nsurlrequest URL of the different processing//js in the data will be passed as a URL redirection var tempurl = "The value to be passed"; window.location.href= encodeURI (encodeURI (Tempurl));
WebView Proxy Redirection-(BOOL) WebView: (UIWebView *) WebView shouldstartloadwithrequest: (nsurlrequest *) request Navigationtype: (uiwebviewnavigationtype) navigationtype{ nsstring *requeststring = [[Request URL] Absolutestring] stringbyreplacingpercentescapesusingencoding:nsutf8stringencoding]; NSLog (@ "should-------"); if ([requeststring hasprefix:@ "url://"]) { //According to the rules that you define, call OC's method through the value of the string. Here is the output of the string. NSLog (@ "===%@", requeststring); } return YES;}