【问题标题】:airwatch-sdk-plugin not recognised in ionic 3 app在 ionic 3 应用程序中无法识别 airwatch-sdk-plugin
【发布时间】:2018-09-14 09:52:06
【问题描述】:

我创建了一个全新的空白 ionic 3 应用并运行命令“npm i airwatch-sdk-plugin”,然后运行“ionic cordova platform add android”。

在 app.components 我有这段代码...

import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';

import { HomePage } from '../pages/home/home';
@Component({
  templateUrl: 'app.html'
})
export class MyApp {
  rootPage:any = HomePage;

  constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {
    platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      statusBar.styleDefault();
      splashScreen.hide();

      window.plugins.airwatch.setSDKEventListener( function( event, error ) {
        if( event === "initSuccess" ) {
          alert( 'airwatch initialised' );
        }
      },
      (error) => {
        alert( 'airwatch error: ' + JSON.stringify( error ) );
      });
      
    });
  }
}

Windows 10 上的编辑器 Visual Studio Code 报告类型窗口上不存在插件。我可以将此行更改为...

(<any>window).plugins

要删除编辑器错误,但是当我使用“ionic serve”运行项目时,浏览器会报告此错误...

TypeError: 无法读取未定义的属性“airwatch”

我做错了什么?

【问题讨论】:

    标签: ionic3 airwatch


    【解决方案1】:

    根据安装指南,应在将任何其他插件添加到应用程序之前添加以下命令:

    ionic cordova plugin add airwatch-sdk-plugin 
    

    根据安装指南,window.plugins.airwatch 对象中提供了这些功能。因此,您需要声明window 变量,如下所示:

    declare var window: any;
    

    希望对你有帮助。

    【讨论】:

    • 我已经删除了所有插件,所以插件目录是空的。我卸载了 airwatch-sdk-plugin。我还卸载了 Adnroid 平台。然后我重新安装了 airwatch-sdk-plugin 并把 declare var window: any;在@Component 上面和platform.ready 里面我放了代码window.plugins.airwatch.setSDKEventListener(event,info) 代码。我收到此错误...无法读取未定义的属性“airwatch”。有什么想法吗?
    • 只是想知道,您是否也在使用 ionic cordova run android 和真机进行测试?
    • 我正在使用 ionic cordova build android 并在设备上运行。我也安装了intentShim 并调用它... window.plugins.intentShim 并通过Chrome:inspect 我可以在那里放置一个断点,我可以看到window.plugins 中列出的只是intentShim 而不是airwatch插入。显然,这表明插件没有正确安装。如果我要从一个全新的项目开始... ionic start airwatch blank,步骤是什么?
    • 我的 ionic.info 报告了这个... Ionic: ionic (Ionic CLI) : 4.0.5 (C:\Users\Graham.Simmons\AppData\Roaming\npm\node_modules\ionic) Ionic Framework :离子角 3.9.2 @ionic/app-scripts:3.1.10 Cordova:cordova(Cordova CLI):8.0.0 Cordova 平台:android 7.0.0 系统:Android SDK 工具:26.1.1 NodeJS:v6.10.3( C:\Program Files\nodejs\node.exe) npm:4.6.1 操作系统:Windows 10
    • 请问您是如何安装插件的?即使用“cordova plugin add airwatch-sdk-plugin”或“npm i airwatch-sdk-plugin”。你也可以试试这个命令“ionic cordova plugin ls”
    猜你喜欢
    • 2019-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-28
    • 1970-01-01
    • 2016-05-04
    • 1970-01-01
    相关资源
    最近更新 更多