EddyVerbruggen / Insomnia-PhoneGap-Plugin

:sleepy: Prevent the screen of the mobile device from falling asleep

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ionic2 not working with background-geolocation

nimeso opened this issue · comments

App.module.ts

import { BackgroundGeolocation } from '@ionic-native/background-geolocation';
import { Geolocation } from '@ionic-native/geolocation';
import { BackgroundMode } from '@ionic-native/background-mode';
import { Insomnia } from '@ionic-native/insomnia';
....
providers: [ 
    BackgroundMode,
    Insomnia,
    BackgroundGeolocation,
    Geolocation
]

app.components.ts

import { BackgroundMode } from '@ionic-native/background-mode';
import { Insomnia } from '@ionic-native/insomnia'
...
constructor(platform: Platform,
              statusBar: StatusBar,
              splashScreen: SplashScreen,
              public member:Member,
              public backgroundMode: BackgroundMode,
              public insomnia: Insomnia
              ) {
platform.ready().then(() => {
      statusBar.styleDefault();
      splashScreen.hide();
      this.backgroundMode.enable();
      this.insomnia.keepAwake()
        .then(
          () => console.log('success'),
          () => console.log('error')
        );
    });
}

What am I doing wrong? It works great but once the app is in the background it works fine BUT after about 40secs, it all stops working, No GPS tracking and BLE button we have stops working.

Any help would be great :)

Euhm, this plugin ONLY keeps the screen on when in the foreground. That's what it's for. Amdroid doesn't allow your app to dictate the screen settings when it's not the foreground app.

@EddyVerbruggen - Any way or Objective-c code for iOS by which I can keep my app running while in background also? Also when we directly lock screen when app is open?