Toast build for orsay 不起作用
Toast build for orsay not working
我用 TOAST 项目为智能电视创建了一个应用程序。在开发过程中,我用 tizen 模拟器和 tizen studio 测试了一切,一切都很好。
完成开发后,我尝试 运行 orsay TV 和 orsay 模拟器上的应用程序,不幸的是,该平台存在很多问题。我修复了设计中的一些问题,但无法解决主要问题。
当我 运行 应用程序时,控制台中有一行显示:deviceready has not fired after 5 seconds
。而且我无法使用任何 TOAST api 功能。
我创建了一个空项目并完全按照此页面上的说明进行操作:https://github.com/Samsung/cordova-plugin-toast#prepare-to-start
但是我又遇到了同样的错误。请帮助我。
这是日志:
cordova/platform: orsay bootstrap BEGIN cordova.js:1365
adding proxy for NetworkStatus cordova.js:887
adding proxy for Console cordova.js:887
adding proxy for Device cordova.js:887
adding proxy for Globalization cordova.js:887
cordova/platform: orsay bootstrap END cordova.js:1460
adding proxy for toast.inputdevice cordova.js:1880
return Window cordova.js:1880
adding proxy for toast.tvwindow cordova.js:1880
return Window cordova.js:1880
adding proxy for toast.tvchannel cordova.js:1880
adding proxy for toast.tvaudiocontrol cordova.js:1880
adding proxy for toast.drminfo cordova.js:1880
adding proxy for toast.application cordova.js:1880
adding proxy for toast.Media cordova.js:1880
Failed to load resource: fail to read a resource form decryptied file file:///home/smarttv/Apps/xThreeApp/cordova_plugins.js
deviceready has not fired after 5 seconds. cordova.js:1880
Channel not fired: onNativeReady cordova.js:1880
Channel not fired: onCordovaReady cordova.js:1880
Channel not fired: onCordovaConnectionReady cordova.js:1880
Channel not fired: onCordovaInfoReady cordova.js:1880
更新:
好的,我刚发现两件事:
- 当我 运行 模拟器上带有
Debug As/Samsung Smart Tv Emulator
的应用程序时 devicereaday
不会触发,但如果我在模拟器中关闭应用程序并再次从应用程序打开它模拟器中的页面,deviceready
事件将完美运行
- 即使使用上述技巧,当我导航到第二页时,
deviceready
也不会触发! (即使我试图导航到当前页面,但第二次尝试将无法触发 deviceready
事件)
我尝试了很多方法来导航到第二页,但结果都是一样的。 (我使用像 window.location.href = url;
和 window.location.replace(url);
和...这样的方法)
好吧,我自己回答,这是 cordova.js
中的错误
要解决此问题,您可以将 bootstrap 函数更改为 cordova.js 中的以下源代码:
bootstrap: function() {
console.log('cordova/platform: orsay bootstrap BEGIN');
var modulemapper = require('cordova/modulemapper');
var channel = require('cordova/channel');
var SEF = require('cordova/plugin/SEF');
var isWebapisLoaded = false;
var isOnShowEventFire = false;
modulemapper.clobbers('cordova/exec/proxy', 'cordova.commandProxy');
var fireNativeReadyEvent = function() {
if(isWebapisLoaded && isOnShowEventFire) {
channel.onNativeReady.fire();
}
};
for (var k in define.moduleMap) {
if (/cordova.*\/proxy/.exec(k)) {
require(k);
}
if (/cordova.*\/symbols/.exec(k)) {
require(k);
}
}
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = '$MANAGER_WIDGET/Common/webapi/1.0/webapis.js';
script.onload = function() {
isWebapisLoaded = true;
fireNativeReadyEvent();
require('cordova/plugin/ime-via-input');
};
head.appendChild(script);
window.onPause = function () {
channel.onPause.fire();
};
window.onResume = function () {
channel.onResume.fire();
};
window.onHide = function() {
localStorage.clear();
};
window.addEventListener('load', function () {
var AppCommonPlugin = null;
var NNaviPlugin = null;
window.onShow = function () {
localStorage.setItem('showEventFlag', 'true');
settingInfo();
};
if(localStorage.getItem('showEventFlag') == 'true') {
settingInfo();
}
if(window.curWidget && typeof window.curWidget.setPreference == 'function') {
console.log('window.curWidget');
window.curWidget.setPreference('ready', 'true');
}
});
window.addEventListener('unload', function () {
SEF.close();
});
window.addEventListener('keydown', function (e) {
switch(e.keyCode) {
case 88: // RETURN key
// default action disabled.
// Calling 'setPreference('return', 'true')' is needed explicitly to exit the application
e.preventDefault();
break;
case 45: // EXIT key
// NOTHING to prevent.
break;
}
});
function settingInfo() {
try {
AppCommonPlugin = SEF.get('AppCommon');
}
catch(e) {
Error(e);
}
AppCommonPlugin.Execute('UnregisterAllKey');
AppCommonPlugin.Execute('RegisterKey',29460); //up
AppCommonPlugin.Execute('RegisterKey',29461); //down
AppCommonPlugin.Execute('RegisterKey',4); //left
AppCommonPlugin.Execute('RegisterKey',5); //right
AppCommonPlugin.Execute('RegisterKey',29443); //enter
AppCommonPlugin.Execute('RegisterKey',88); // return
try {
NNaviPlugin = SEF.get('NNavi');
}
catch(e) {
Error(e);
}
NNaviPlugin.Execute('SetBannerState',2);
isOnShowEventFire = true;
fireNativeReadyEvent();
}
// End of bootstrap
console.log('cordova/platform: orsay bootstrap END');
}
我用 TOAST 项目为智能电视创建了一个应用程序。在开发过程中,我用 tizen 模拟器和 tizen studio 测试了一切,一切都很好。
完成开发后,我尝试 运行 orsay TV 和 orsay 模拟器上的应用程序,不幸的是,该平台存在很多问题。我修复了设计中的一些问题,但无法解决主要问题。
当我 运行 应用程序时,控制台中有一行显示:deviceready has not fired after 5 seconds
。而且我无法使用任何 TOAST api 功能。
我创建了一个空项目并完全按照此页面上的说明进行操作:https://github.com/Samsung/cordova-plugin-toast#prepare-to-start
但是我又遇到了同样的错误。请帮助我。
这是日志:
cordova/platform: orsay bootstrap BEGIN cordova.js:1365
adding proxy for NetworkStatus cordova.js:887
adding proxy for Console cordova.js:887
adding proxy for Device cordova.js:887
adding proxy for Globalization cordova.js:887
cordova/platform: orsay bootstrap END cordova.js:1460
adding proxy for toast.inputdevice cordova.js:1880
return Window cordova.js:1880
adding proxy for toast.tvwindow cordova.js:1880
return Window cordova.js:1880
adding proxy for toast.tvchannel cordova.js:1880
adding proxy for toast.tvaudiocontrol cordova.js:1880
adding proxy for toast.drminfo cordova.js:1880
adding proxy for toast.application cordova.js:1880
adding proxy for toast.Media cordova.js:1880
Failed to load resource: fail to read a resource form decryptied file file:///home/smarttv/Apps/xThreeApp/cordova_plugins.js
deviceready has not fired after 5 seconds. cordova.js:1880
Channel not fired: onNativeReady cordova.js:1880
Channel not fired: onCordovaReady cordova.js:1880
Channel not fired: onCordovaConnectionReady cordova.js:1880
Channel not fired: onCordovaInfoReady cordova.js:1880
更新:
好的,我刚发现两件事:
- 当我 运行 模拟器上带有
Debug As/Samsung Smart Tv Emulator
的应用程序时devicereaday
不会触发,但如果我在模拟器中关闭应用程序并再次从应用程序打开它模拟器中的页面,deviceready
事件将完美运行 - 即使使用上述技巧,当我导航到第二页时,
deviceready
也不会触发! (即使我试图导航到当前页面,但第二次尝试将无法触发deviceready
事件)
我尝试了很多方法来导航到第二页,但结果都是一样的。 (我使用像 window.location.href = url;
和 window.location.replace(url);
和...这样的方法)
好吧,我自己回答,这是 cordova.js
中的错误要解决此问题,您可以将 bootstrap 函数更改为 cordova.js 中的以下源代码:
bootstrap: function() {
console.log('cordova/platform: orsay bootstrap BEGIN');
var modulemapper = require('cordova/modulemapper');
var channel = require('cordova/channel');
var SEF = require('cordova/plugin/SEF');
var isWebapisLoaded = false;
var isOnShowEventFire = false;
modulemapper.clobbers('cordova/exec/proxy', 'cordova.commandProxy');
var fireNativeReadyEvent = function() {
if(isWebapisLoaded && isOnShowEventFire) {
channel.onNativeReady.fire();
}
};
for (var k in define.moduleMap) {
if (/cordova.*\/proxy/.exec(k)) {
require(k);
}
if (/cordova.*\/symbols/.exec(k)) {
require(k);
}
}
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = '$MANAGER_WIDGET/Common/webapi/1.0/webapis.js';
script.onload = function() {
isWebapisLoaded = true;
fireNativeReadyEvent();
require('cordova/plugin/ime-via-input');
};
head.appendChild(script);
window.onPause = function () {
channel.onPause.fire();
};
window.onResume = function () {
channel.onResume.fire();
};
window.onHide = function() {
localStorage.clear();
};
window.addEventListener('load', function () {
var AppCommonPlugin = null;
var NNaviPlugin = null;
window.onShow = function () {
localStorage.setItem('showEventFlag', 'true');
settingInfo();
};
if(localStorage.getItem('showEventFlag') == 'true') {
settingInfo();
}
if(window.curWidget && typeof window.curWidget.setPreference == 'function') {
console.log('window.curWidget');
window.curWidget.setPreference('ready', 'true');
}
});
window.addEventListener('unload', function () {
SEF.close();
});
window.addEventListener('keydown', function (e) {
switch(e.keyCode) {
case 88: // RETURN key
// default action disabled.
// Calling 'setPreference('return', 'true')' is needed explicitly to exit the application
e.preventDefault();
break;
case 45: // EXIT key
// NOTHING to prevent.
break;
}
});
function settingInfo() {
try {
AppCommonPlugin = SEF.get('AppCommon');
}
catch(e) {
Error(e);
}
AppCommonPlugin.Execute('UnregisterAllKey');
AppCommonPlugin.Execute('RegisterKey',29460); //up
AppCommonPlugin.Execute('RegisterKey',29461); //down
AppCommonPlugin.Execute('RegisterKey',4); //left
AppCommonPlugin.Execute('RegisterKey',5); //right
AppCommonPlugin.Execute('RegisterKey',29443); //enter
AppCommonPlugin.Execute('RegisterKey',88); // return
try {
NNaviPlugin = SEF.get('NNavi');
}
catch(e) {
Error(e);
}
NNaviPlugin.Execute('SetBannerState',2);
isOnShowEventFire = true;
fireNativeReadyEvent();
}
// End of bootstrap
console.log('cordova/platform: orsay bootstrap END');
}