就ios而言,就可以利用"WebKit"了
今天就先討論從javascript丟回來呼叫xamarin UI怎麼做
==============某個要查看網頁的viewcontroller======
public partial class MyMapViewController : UIViewController, IWKScriptMessageHandler {
public MyMapViewController () : base("MyMapViewController ", null) {
}
public override void DidReceiveMemoryWarning() {
base.DidReceiveMemoryWarning();
// Release any cached data, images, etc that aren't in use.
}
public override void ViewDidLoad() {
base.ViewDidLoad();
var userController = new WKUserContentController();
userController.AddScriptMessageHandler(this, "myApp");
var config = new WKWebViewConfiguration {
UserContentController = userController
};
var webkitView= new WebKit.WKWebView(viewContainScroll.Frame, config);
webkitView.LoadRequest(new Foundation.NSUrlRequest(new NSUrl("你的web網址")));
webkitView.ContentMode = UIViewContentMode.ScaleToFill;
this.View.AddSubview(webkitView);
}
public void DidReceiveScriptMessage(WKUserContentController userContentController, WKScriptMessage message) {
var msg = message.Body.ToString();
System.Diagnostics.Debug.WriteLine(msg);
}
手機端好了,再來就是看遙遠的雲端了
===============================
<html>
<body>
<script type="text/javascript">
//找個按鈕觸發這個doCallBack吧
var doCallBack = function ( paraStr) {
//以下的動作就會呼叫包含他的webkitview所AddScriptMessageHandler的物件的
//「DidReceiveScriptMessage」的函數來接受訊息了
window.webkit.messageHandlers.myApp.postMessage("param=" + paraStr);
}
...
...
.....
</script>
</body>
</html>
================================
完整的討論來源,請參考這裡
現在的前端的工程師不只是二刀流的,
通常是剪刀菜刀剃頭刀手術刀小李飛刀都要會了