The use of UIView.
How to load local HTML:
var context = (Jscontext) Webview.valueforkeypath ((nsstring) "DocumentView.webView.mainFrame.javaScriptContext"); Context. Exceptionhandler = (Jscontext context2, jsvalue exception) = { Console.WriteLine ("JS exception: {0}", exception); }; You can use JS to invoke C # code, like Android, by invoking the C # method by using the Mycsharpobject object var myexporter = new Myjsexporter (); context[(nsstring) "mycsharpobject"] = Jsvalue.from (myexporter, context); var nsurl = new Nsurl ("demotest.html", false); var nsrequest = Nsurlrequest.fromurl (nsurl); Nsurl URL = NSBundle.MainBundle.GetUrlForResource ("main", "HTML"); String htmlstring = Nsstring.fromdata (Nsdata.fromurl (URL), Nsstringencoding.utf8); Webview.loadhtmlstring (htmlstring, NSBUNDLE.MAINBUNDLE.BUNDLEURL);
declaring interfaces
<summary> ///JS calling the C # code method interface ///</summary> [Protocol ()] interface Imyjsvisibleprotocol:ijsexport { [Export ("MyFunc")] int myFunc (); [Export ("Arity2:with:")] NSObject Arity2with (nsobject arg1, NSObject arg2); }
Implementation method
<summary>///Method realization/// </summary> class Myjsexporter:nsobject, imyjsvisibleprotocol< c13/>{public int MyFunc () { Console.WriteLine ("called!"); return; } Public NSObject Arity2with (nsobject arg1, nsobject arg2) { Console.WriteLine ("Arity 2 function called with" + A Rg1 + "" + arg2); return (NSNumber);} }
JS Call
<script type= "Text/javascript" > function Callxamobject () { //' mycsharpobject ' injected into JS context By C # code ' context [(nsstring) "mycsharpobject"] = Jsvalue.from (... etc ... ' alert ("123"); var resultcalculatedincsharp = Mycsharpobject.myfunc (); document.getElementById ("Output"). InnerHTML = Resultcalculatedincsharp; } function Callarity2method () {//note How this is mapped by [Export ("Arity2:with:")] var result = Mycsharpobject.a Rity2with ("foo", "Bar"); } </script>