0

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?

user1753622
  • 287
  • 3
  • 19

1 Answers1

0

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.

Sandy.....
  • 2,833
  • 2
  • 15
  • 26
  • I've removed all plugins, so the plugins directory is empty. I uninstalled the airwatch-sdk-plugin. I also uninstalled the Adnroid platform. I then re-installed the airwatch-sdk-plugin and put declare var window: any; above @Component and inside the platform.ready I put the code window.plugins.airwatch.setSDKEventListener(event,info) code. I get this error ... Cannot read property 'airwatch' of undefined. Any ideas? – user1753622 Sep 17 '18 at 09:26
  • Just want to know, whether you are using ionic cordova run android and real devices too for testing? – Sandy..... Sep 17 '18 at 09:47
  • I'm using ionic cordova build android and running on device. I also have the intentShim installed and to call that I do .... window.plugins.intentShim and via Chrome:inspect I can put a breakpoint there and I can see that within window.plugins is just the intentShim listed and not the airwatch plugin. Obviously, this would suggect the plugin isn't installed properly. What would the steps be if I was to start from a brand new project ... ionic start airwatch blank ? – user1753622 Sep 17 '18 at 10:02
  • My ionic.info reports this ... Ionic: ionic (Ionic CLI) : 4.0.5 (C:\Users\Graham.Simmons\AppData\Roaming\npm\node_modules\ionic) Ionic Framework : ionic-angular 3.9.2 @ionic/app-scripts : 3.1.10 Cordova: cordova (Cordova CLI) : 8.0.0 Cordova Platforms : android 7.0.0 System: Android SDK Tools : 26.1.1 NodeJS : v6.10.3 (C:\Program Files\nodejs\node.exe) npm : 4.6.1 OS : Windows 10 – user1753622 Sep 17 '18 at 10:03
  • May I know how you have installed the plugin? i.e. using "cordova plugin add airwatch-sdk-plugin" or "npm i airwatch-sdk-plugin". Also can you please try this command "ionic cordova plugin ls" – Sandy..... Sep 17 '18 at 10:14
  • I used this ... npm i airwatch-sdk-plugin and running the other command I get ... $ ionic cordova plugin ls > cordova plugin ls No plugins added. Use `cordova plugin add `. – user1753622 Sep 17 '18 at 10:34
  • and this too (was too big to paste in with last results) .... net.js:654 throw new TypeError( ^ TypeError: Invalid data, chunk must be a string or buffer, not object at Socket.write (net.js:654:11) at process. (C:\Users\Graham.Simmons\AppData\Roaming\npm\node_modules\ionic\bin\ionic:9:63) at emitTwo (events.js:106:13) at process.emit (events.js:191:7) at emitPendingUnhandledRejections (internal/process/promises.js:66:22) at process._tickCallback (internal/process/next_tick.js:110:7) – user1753622 Sep 17 '18 at 10:34
  • I've just uninstalled the npm version and installed the cordova plugin add airwatch-sdk-plugin version and now ionic cordova plugin ls shows > cordova plugin ls com.airwatch.awsdkplugin 1.2.0 "airwatch-sdk-plugin" – user1753622 Sep 17 '18 at 10:55
  • Please try running the app now – Sandy..... Sep 17 '18 at 10:57
  • ionic cordova build android fails with this error ... Could not resolve all files for configuration ':app:debugCompileClasspath'. and also Could not find :AirWatchSDK-release-17.6.3.2-SNAPSHOT:. – user1753622 Sep 17 '18 at 11:06
  • Am I missing some configuration? – user1753622 Sep 17 '18 at 13:28
  • Do I need to install some SDK to the Android Studio so the build knows what airwatch is? If so, what do I need to do? Please help as I'm going around in circles here. – user1753622 Sep 18 '18 at 08:36