seididieci / capacitor-backround-geolocation

Ionic capacitor backgroung geolocation Plugin
MIT License
12 stars 2 forks source link

Background logic onLocations does not work while the app is unactive(in background) #9

Closed SalahAdDin closed 3 years ago

SalahAdDin commented 3 years ago

Testing this we have the next behavior: when the app is active(there is no smallIcon), the background task is working normally(a log with the location), but when we send the app to background, unactive, the log is not shown.

My service code is this:

const init = () => {
  BackgroundGeolocation.initialize({
    notificationText: "Your app is running, tap to open.",
    notificationTitle: "App Running",
    updateInteval: 10000,
    requestedAccuracy: 102,
    smallIcon: "ic_small_icon",
    startImmediately: false,
  })

  BackgroundGeolocation.addListener("onPermissions", (data: BgPermissions) => {
    console.log("BGLocation permissions:", data)
  })

  BackgroundGeolocation.addListener("onLocation", (location: BgLocationEvent) => {
    console.log("Background geolocation: ", location)
  })

  BackgroundGeolocation.start()
}

const start = () => BackgroundGeolocation.start()

const stop = () => BackgroundGeolocation.stop()

const goForeground = () => BackgroundGeolocation.goForeground()

const getLocation = (fn: (location: BgLocationEvent) => void) =>
  BackgroundGeolocation.addListener("onLocation", (location: BgLocationEvent) => {
    fn(location)
  })

export const geoLocationService = { init, goForeground, getLocation, start, stop }

And i'm calling it here in the App:

  useEffect(() => {
    fcmService.init()
    geoLocationService.init()
    loadUserData()
    loadConfData()
  }, []);

To Reproduce Steps to reproduce the behavior:

  1. Open de App
  2. Navigate to maps
  3. Go to mobile desktop or another app
  4. Go to the console and view the logs

Expected behavior We should see the logs coming even when the app in unactive.

Screenshots You can see in the following screen shot how while the app is unactive, the console is not sending logs?: Captura de Pantalla 2020-10-28 a la(s) 10 32 06

Desktop (please complete the following information):

Smartphone (please complete the following information):

SalahAdDin commented 3 years ago

@seididieci Any idea about this behavior?