airwatch-sdk-plugin not recognised in ionic 3 app

409 views Asked by At

I've created a brand new blank ionic 3 app and run the command "npm i airwatch-sdk-plugin" and then "ionic cordova platform add android".

In app.components I have this code ...

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 ) );
      });
      
    });
  }
}

The editor Visual Studio Code on Windows 10 is reporting the plugins does not exist on type window. I can change this line to ...

(<any>window).plugins

to remove the editor error, but when I run the project with "ionic serve" the browser will report this error ...

TypeError: Cannot read property 'airwatch' of undefined

What am I doing wrong?

1

There are 1 answers

12
Sandy..... On

As per the installation guide, below command should be added before any other plugin is added to the app:

ionic cordova plugin add airwatch-sdk-plugin 

As per the installation guide, the functions are available in the window.plugins.airwatch object. Hence you need to declare window variable as shown below:

declare var window: any;

Hope it will help you.