HaylLtd / cordova-background-geolocation-plugin

Background and foreground geolocation plugin for Cordova.
Apache License 2.0
56 stars 64 forks source link

Problems to get to work on Ios #151

Open raul203al opened 1 year ago

raul203al commented 1 year ago

Hello, actually I'm using this plugin on capacitor i got it to work for Android Devices but when it comes to Iphone devices i only get troubles actually I modified the info pList with:

This is my configuration:

  await backgroundGeolocation.configure({
    interval: 5000,
    desiredAccuracy: 0,
    startForeground: true, 
    stopOnTerminate: true, 
    stationaryRadius: 100, 
    distanceFilter: 0, 
    notificationTitle: 'Location Enabled', 
    notificationText: 'Enabled', 
    locationProvider: backgroundGeolocation.DISTANCE_FILTER_PROVIDER, 
    postTemplate: postTemplate
  });

And this is my on event code:

  backgroundGeolocation.on('location', async () => {
    console.log("ENTRA LOC")
    if (!navigator.onLine) {
      return;
    }
    this.locationUpdate(await this.getLocationData());
  });

Finally the xcode log:

2023-06-13 13:52:44.140120+0200 App[88984:1058797] CDVBackgroundGeolocation #onAuthorizationChanged 2023-06-13 13:52:44.140804+0200 App[88984:1059078] Configuration persisted successfully 2023-06-13 13:52:44:140 App[88984:1058797] LocationManager didChangeAuthorizationStatus 4 2023-06-13 13:52:44.144086+0200 App[88984:1058880] LocationManager didChangeAuthorizationStatus 4 2023-06-13 13:52:44:158 App[88984:1058797] DistanceFilterLocationProvider will start 2023-06-13 13:52:44.161157+0200 App[88984:1058880] DistanceFilterLocationProvider will start 2023-06-13 13:52:44:174 App[88984:1058797] DistanceFilterLocationProvider switchMode 1 2023-06-13 13:52:44.179519+0200 App[88984:1058881] DistanceFilterLocationProvider switchMode 1 2023-06-13 13:52:44:191 App[88984:1058797] DistanceFilterLocationProvider didUpdateLocations (operationMode: 1) 2023-06-13 13:52:44:193 App[88984:1058797] Location age 0.437930 ⚡️ [log] - EMPIEZA LOC ⚡️ [log] - FetchLocation: 9 This FetchLocation Isn't related with this ⚡️ [log] - 1 2023-06-13 13:52:44:263 App[88984:1058797] DistanceFilterLocationProvider didUpdateLocations (operationMode: 1) 2023-06-13 13:52:44:263 App[88984:1058797] Location age 0.111447

As you can see in the log it shows my console log but it never execute the function (inside the functions there are more logs)

HarelM commented 1 year ago

Have you played with the configuration? Distance filter of 0 while using distance provider send like a bad idea, but it might work IDK. I'm using raw provider and it is working as expected on iOS for me.

raul203al commented 1 year ago

Thanks for answer so fast now wI have another problem with the sqlite database it doesn't create the necessary tables should I need to add something to the config or related on Android works well

raul203al commented 1 year ago

Hi?

HarelM commented 1 year ago

I have it working on iOS, I can't debug your app...

raul203al commented 1 year ago

I know you can't debug my app but may something is wrong with my config, maybe the import?

HarelM commented 1 year ago

I don't know... Sorry... This is the service I wrote which I know works: https://github.com/IsraelHikingMap/Site/blob/f61c4539708af08e3cb3f93534670ff552cddb31/IsraelHiking.Web/src/application/services/geo-location.service.ts

raul203al commented 1 year ago

Thanks i got it to work last thing is it posible to set a location interval for iOS?

raul203al commented 1 year ago

Does the interval works for ios in that service?

tsanko95 commented 1 year ago

Thanks i got it to work last thing is it posible to set a location interval for iOS?

Hi Raúl, how did you make it works ? Gracias :)

raul203al commented 1 year ago

Hi tsanko I couldn´t make it works on ios, actually I´m doing other things probably in the some weeks I´ll give it another try if I get it to work I´ll dm you or reply this

risinghero commented 9 months ago

Do events really work in backround mode? I think that they dont... Because they require javascript and webview

HarelM commented 9 months ago

They work to a certain limit, I also think it's different between capacitor and Cordova. Generally speaking, my approach was to trust the db of the plugin and not the state of the webview.

risinghero commented 8 months ago

I think that in cordova they just dont work in background mode. Cause webview gets destroyed. And javascript code just cant be executed. Events are only for foreground mode. But you can get all locations when your app is activated and brought to foreground and then log.