HaylLtd/cordova-background-geolocation-plugin

Problems to get to work on Ios

Opened this issue · 13 comments

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:

  • Privacy - Location Always and When In Use Usage Description
  • Privacy - Location When In Use Usage Description
    and also on the capabilities I checked the location updates, fetch and background processing

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

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.

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

Hi?

HarelM commented

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

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

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

Does the interval works for ios in that service?

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 :)

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

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

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.

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.