onDeviceReady 未在 Cordova 中触发 Windows 10 个应用程序仅在发布模式下

onDeviceReady not firing in Cordova Windows 10 app only in Release mode

我有一个 Sencha Touch 应用程序,它在 Windows 10 周年更新发布之前一直没有问题。使用新的 SDK,我的应用程序的 onDeviceReady 事件在我构建商店包后不会被触发。 但它在调试模式下完美运行

我认为这与 .NET 本机工具链有关。但经过 3 天的故障排除和大量谷歌搜索后,我仍然迷路了。这是我已经尝试过的方法:

下面是我安装的插件列表。

com.phonegap.plugins.PushPlugin 2.5.0 "PushPlugin"
com.verso.cordova.clipboard 0.1.0 "Clipboard"
cordova-plugin-camera 2.3.0 "Camera"
cordova-plugin-compat 1.1.0 "Compat"
cordova-plugin-contacts 2.2.0 "Contacts"
cordova-plugin-device 1.1.3 "Device"
cordova-plugin-device-orientation 1.0.4 "Device Orientation"
cordova-plugin-file 4.3.0 "File"
cordova-plugin-geolocation 2.4.0 "Geolocation"
cordova-plugin-inappbrowser 1.5.0 "InAppBrowser"
cordova-plugin-media 2.4.0 "Media"
cordova-plugin-network-information 1.3.0 "Network Information"
cordova-plugin-screen-orientation 1.4.2 "Screen Orientation"
cordova-plugin-statusbar 2.2.0 "StatusBar"
cordova-plugin-whitelist 1.3.0 "Whitelist"
cordova-sms-plugin 0.1.11 "Cordova SMS Plugin"
cordova.plugins.navbar 1.0.0 "NavBar"
phonegap-plugin-push 1.9.0 "PushPlugin"

我怀疑 body onload 事件是否没有被触发。因此,我也在 html 主体内的脚本标记内调用了 onLoad() 函数。运气不好。

index.html正文

<body onload="onLoad()">
    <div id="appLoadingIndicator"></div>
    <script type="text/javascript">
        onLoad();
        var apploading = document.getElementById('appLoadingIndicator');
        apploading.style.lineHeight = document.body.clientHeight + 'px';
        var img = document.createElement('img');
        img.setAttribute('src', resourceURL + '/loading/logo-splash.png');
        apploading.appendChild(img);
    </script>
</body>

onLoad函数定义

function onLoad() {
    console.log('xxxxxx addEventListener onDeviceReady');
    document.addEventListener("deviceready", onDeviceReady, false);
    document.addEventListener("resume", onDeviceResume, false);
}

有没有人遇到过类似的问题?对此的任何提示都会非常有帮助。

我发现 onDeviceReady 实际上在触发,但只是在 5 秒以上之后。 Sencha Touch 应用程序在触发 onDeviceReady 之前加载,应用程序在启动期间访问 device 对象,即 undefined。这导致应用程序崩溃。因此,在 onDeviceReady 处理程序中触发应用程序启动就可以了。

onDeviceReady() 在 index.html

function onDeviceReady() {
    if (Ext.os.is.Phone) {
        myApp.app.launchPhone();
    } else {
        myApp.app.launchTablet();
    }
    ...
}

在app.js

中启动()
launch: function() {
   // left empty intentionally
}