我正在接管 Cordova/Ionic 项目。我以前从未使用过 Cordova 或 Ionic,所以我在该领域完全是初学者。然而,我断断续续地使用 Node 已经有几年了,所以我对此基本了解。
一个简单的启动任务,我需要添加Appsee:
https://www.appsee.com/docs/ios/ionic
这部分很简单:
In case you're using TypeScript (default in ionic 2 and ionic 3) place the following line under the imports:
declare var Appsee:any;
我放入此文件中:
./src/app/app.component.ts
但这部分不太明显:
Call the following method when your app starts, preferably when the deviceready event fires:
Appsee.start("YOUR API KEY");
所以我运行 grep 来找出 deviceready 的位置:
grep -iR "deviceready" * | grep -v node_modules
www/build/vendor.js: * resolve when Cordova triggers the `deviceready` event.
www/build/vendor.js: // prepare a custom "ready" for cordova "deviceready"
www/build/vendor.js: doc.addEventListener('deviceready', function () {
www/build/vendor.js: // 3) cordova deviceready event triggered
www/build/vendor.js: var deviceReady = new Promise(function (resolve, reject) {
www/build/vendor.js: document.addEventListener("deviceready", function () {
www/build/vendor.js: var deviceReadyDone = deviceReady.catch(function () {
www/build/vendor.js: return deviceReadyDone.then(function () {
www/build/vendor.js: document.addEventListener('deviceready', function () {
www/build/vendor.js: console.log("Ionic Native: deviceready event fired after " + (Date.now() - before) + " ms");
www/build/vendor.js: console.warn("Ionic Native: deviceready did not fire within " + DEVICE_READY_TIMEOUT + "ms. This can happen when plugins are in an inconsistent state. Try removing plugins from plugins/ and reinstalling them.");
所以我只在 build
文件夹中看到“deviceready”。我想我应该避免编辑 build
内部的任何内容?那不是充满了 Ionic/Cordova 生成的东西吗?
我在哪里可以使用 deviceready 注册某些内容?
如果我运行:
ionic info
我得到:
[WARN] Detected locally installed Ionic CLI, but it's too old--using global CLI.
cli packages: (/usr/local/lib/node_modules)
@ionic/cli-utils : 1.19.2
ionic (Ionic CLI) : 3.20.0
global packages:
cordova (Cordova CLI) : 8.0.0
local packages:
@ionic/app-scripts : 2.1.4
Cordova Platforms : none
Ionic Framework : ionic-angular 3.6.0
System:
ios-deploy : 1.9.2
Node : v6.5.0
npm : 3.10.3
OS : OS X El Capitan
Xcode : Xcode 7.3.1 Build version 7D1014
Environment Variables:
ANDROID_HOME : not set
Misc:
backend : pro
我很乐意遵循其他地方的指示。
最佳答案
您应该使用平台在 IONIC 中获取设备就绪事件,在您的 app.component.ts 中
import { Platform } from 'ionic-angular';
Add platform.ready() method inside the constructor as shown below
constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {
platform.ready().then(() => {
// Okay, so the platform is ready.
// Here you can do any higher level native things you might need.
Appsee.start("YOUR API KEY");
statusBar.styleDefault();
splashScreen.hide();
});
}
当设备/平台准备就绪时,它将被触发。 Here is the documentation
关于cordova - 如何在 Cordova/Ionic 项目中使用 deviceready 事件注册代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49325892/