1

I've created a Ionic2 application that needs to post and get data from a API online. This needs to happen even when the app is in background mode or the device is asleep. I've installed https://ionicframework.com/docs/native/background-mode/

app.module.ts has:

import { BackgroundMode } from '@ionic-native/background-mode';
...
export class AppModule {
   constructor(private backgroundMode: BackgroundMode, public platform: Platform) { 
        console.log('Hello app');
        this.platform = platform;
        this.platform.ready().then(() => {
            this.backgroundMode.enable();
        });
   }
}

Am I doing this correctly?

The issue is that it runsing in the background fine UNTIL the device goes in to sleep mode at which point it stops sending data to the API so the whole app fails. see screen grab:

enter image description here

Jamie Barker
  • 163
  • 1
  • 15

1 Answers1

0
  this.backgroundMode.setDefaults({ silent: true })
nuclear kote
  • 480
  • 7
  • 16