EddyVerbruggen / Insomnia-PhoneGap-Plugin

:sleepy: Prevent the screen of the mobile device from falling asleep
264 stars 106 forks source link

Ionic2 not working with background-geolocation #42

Closed nimeso closed 3 years ago

nimeso commented 7 years ago

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 :)
EddyVerbruggen commented 7 years ago

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.

Anuj-logiciel commented 3 years ago

@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?