vs2017 iOS Usage History

Source: Internet
Author: User

  1. 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>

      

  2. JS and CSS resources used in HTML, generated using Bundleresource


vs2017 iOS Usage History

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.