在 Angular 混合应用程序中未触发 deviceready 事件 [英] deviceready Event not fired in an Angular hybrid app
问题描述
我正在构建一个全平台 Angular 6 应用程序,该应用程序将使用 Cordova 8.1.2 进行包装,很遗憾我无法触发 deviceready 事件.
I am building an all platform Angular 6 APP that is going to be wrapped with Cordova 8.1.2 Unfortunately I cannot make the deviceready event to fire.
我有两个单独的项目,一个用于 Angular,一个用于 Cordova,我能够构建以构建 Angular 项目并使用以下命令创建一个 android apk:
I have two separate projects one for Angular and one for Cordova and I am able to build to build the Angular project and create an android apk with the following command:
ng build --prod --base-href . --output-path ../Cordova/CordovaMobileApp/www/ & cd ../Cordova/CordovaMobileApp & cordova run android & cd ../../NxAngularMVI
但是现在我需要使用 Cordova 插件,为此我需要检测 deviceready 事件.
Now however I need to use Cordova plugins and for that I need to detect the deviceready event.
在我的 index.html 头中,我已经包含了:
in my index.html head i have already included:
<script type="text/javascript" src="cordova.js"></script>
在我的 main.ts 文件中,我试图等待事件发生以引导我的应用程序.
and in my main.ts file I am trying to wait for the event to happen to bootstrap my app.
const onDeviceReady = () => {
console.log('Bootstrap ON!');
platformBrowserDynamic().bootstrapModule(AppModule).catch(err =>
console.log(err));
};
document.addEventListener('deviceready', onDeviceReady, false);
应用程序永远不会初始化,因为 deviceready 事件永远不会被触发.我尝试了几种在这种引导方法的堆栈溢出中发现的变体,但无济于事.我尝试重新安装从框架到平台再到插件的每个cordova 部分,但没有任何帮助.我已经在 Galaxy S9 和摩托罗拉 G5 上对其进行了测试.
The app never initializes because the deviceready event is never fired. I have tried several variation that I have found on stack overflow of this bootstrapping method but to no avail. I have tried reinstalling every cordova part from the framework to the platforms to the plugins but nothing helped. I have tested it on an Galaxy S9 and Motorola G5.
由于 Cordova API 提供的这个功能是我的项目所必需的,所以我需要你们的帮助.谢谢!
Since this functionality provided by the Cordova API is a must for my project I need your help guys. Thanks !
推荐答案
已在此线程中回答 有没有办法在 Google Play 上提交 reactjs PWA?,您可以在 Chrome 控制台中调试您的cordova 应用程序,请按照以下步骤操作
As already answered in this thread Is there a way to submit a reactjs PWA on Google Play?, you can debug your cordova application in Chrome console, follow these steps
- 将您的设备与安装的应用程序连接起来(必须是 DEBUG版本,而不是发布)
- 打开 Chrome 控制台,在最后一个标签页附近,您应该会看到一个三垂直点图标,单击它并选择更多工具",然后选择远程"设备",您应该会看到列出的已连接设备.选择它
- 在列表中找到您的应用程序,然后单击检查"按钮,位于此时,您还应该在 Chrome 浏览器中打开您的应用程序.
由于应用程序无法启动,您可以检查 Chrome 控制台是否有错误,让我们知道
Since the application doesn't boot, you can check the Chrome console for errors, let us know
干杯
这篇关于在 Angular 混合应用程序中未触发 deviceready 事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!