使用nativescript-webview-interface并将事件注册到webview。事件已触发应用程序,并且运行正常。但是在nativescript 6中,相同的代码无法正常工作。
var webViewInterfaceModule = require('nativescript-webview-interface');
exports.onWebViewLoaded = function(args){
var webview = args.object;
oWebViewInterface = new webViewInterfaceModule.WebViewInterface(webview, buildSrc());
//构建源返回html字符串
webview.on(webViewModule.WebView.loadFinishedEvent, (args) => {
//do something specific to app
});
oWebViewInterface.on("watchInc", (data) => {
console.log("event watchInc - want to do something app specific");
//not receiving this event
});
oWebViewInterface.on("watchEnd", (data) => {
console.log("event watchEnd - want to do something app specific");
//not receiving this event
}, 200); // Timeout needed as loading event is fired when nothing ready...
}
感谢manoj。已移至nativescript-webview-ext插件,并且webview和javascript之间的通信正常。