vs2017 ios使用曆程

來源:互聯網
上載者:User

標籤:handler   c#   ber   mob   element   mda   tca   bsp   put   

  1. UIView的使用。
    載入本地html的方法:
    var context = (JSContext)WebView.ValueForKeyPath((NSString)"documentView.webView.mainFrame.javaScriptContext");            context.ExceptionHandler = (JSContext context2, JSValue exception) =>            {                Console.WriteLine("JS exception: {0}", exception);            };            //可以使用 js調用 c# 代碼,和安卓一樣,通過使用 myCSharpObject對象調用c#方法            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);

      聲明介面

    /// <summary>        /// js調用c#代碼的方法介面        /// </summary>        [Protocol()]        interface IMyJSVisibleProtocol : IJSExport        {            [Export("myFunc")]            int MyFunc();            [Export("Arity2:With:")]            NSObject Arity2With(NSObject arg1, NSObject arg2);        }

      實現方法

     /// <summary>        /// 方法實現        /// </summary>        class MyJSExporter : NSObject, IMyJSVisibleProtocol        {            public int MyFunc()            {                Console.WriteLine("Called!");                return 42;            }            public NSObject Arity2With(NSObject arg1, NSObject arg2)            {                Console.WriteLine("Arity 2 function called with " + arg1 + " " + arg2);                return (NSNumber)42;            }         }

      js調用

    <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.Arity2With("foo", "bar");        }    </script>

      

  2. html中使用的js和css資源,產生使用 BundleResource

     


     

vs2017 ios使用曆程

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.