Background mode working but failed to execute function


#1

Uncaught TypeError: cordova.plugins.backgroundMode.onactivate is not a function

[code]

declare var cordova: any;

backgroundfunc = function() {
setTimeout( ()=> {
this.backgroundfunc.call(this);
// Modify the currently displayed notification

        console.log('before db ready');
        this.datasync();
        cordova.plugins.backgroundMode.configure({
          text: 'Data Sync. Running.'
        });
      }, 100000);
    }

datasync(){
this.database.isReady(() => {
this.database.syncData().then((data) => {
console.log(“background sync done”)
console.log(data);
},
err => {
console.log(“sync. not done”);
console.log(err);
}
)
});
}

initializeApp() {
this.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();
document.addEventListener(‘deviceready’, function () {

    // Android customization
    cordova.plugins.backgroundMode.setDefaults({ text: 'Doing heavy tasks.' });
    // Enable background mode
    cordova.plugins.backgroundMode.enable();

   
    // Called when background mode has been activated
    cordova.plugins.backgroundMode.onactivate = this.backgroundfunc;

  }, false);

  this.database.isReady(() => {

    this.database.isSignedIn().then(data => {
      if (data) {
        this.rootPage = HomePage;
        Splashscreen.hide();

      } else {
        this.rootPage = LoginPage;

      }
    }, err => {
      Splashscreen.hide();

    })
  })

});

}