注意:
JS 方法必须在 Windows 下, 例: Windows.loginStatus
如果需要返回一些数据给 App, 那么这些数据不能够通过异步来获取, 也不能够有阻断进程的语句如 alert, 否者, App 将不能够获取到正确参数, 而是得到 undefined, 例如在方法里加个 alert('1'), 而 return 在 alert 语句后.
iOS webView 桥接
- Utility.prototype.setupWebViewJavascriptBridge = function (callback) {
- if (Windows.WebViewJavascriptBridge) { return callback(WebViewJavascriptBridge); }
- if (Windows.WVJBCallbacks) { return Windows.WVJBCallbacks.push(callback); }
- Windows.WVJBCallbacks = [callback];
- var WVJBIframe = document.createElement('iframe');
- WVJBIframe.style.display = 'none';
- WVJBIframe.src = 'wvjbscheme://__BRIDGE_LOADED__';
- document.documentElement.appendChild(WVJBIframe);
- setTimeout(function() { document.documentElement.removeChild(WVJBIframe) }, 0)
- }
- Android
- Windows.AndroidWebView[fun]
- // [fun]: 为 Android 中定义的方法
来源: http://www.jianshu.com/p/6204a2877476