react-native-geolocation-service icon indicating copy to clipboard operation
react-native-geolocation-service copied to clipboard

Fetch location problem while app goes in background (ios)

Open kikanikishan opened this issue 2 years ago • 5 comments

Environment

System: OS: macOS 12.6.1 CPU: (4) x64 Intel(R) Core(TM) i5-5250U CPU @ 1.60GHz Memory: 24.20 MB / 8.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 14.18.0 - ~/.nvm/versions/node/v14.18.0/bin/node Yarn: 1.22.19 - /usr/local/bin/yarn npm: 9.1.1 - ~/.nvm/versions/node/v14.18.0/bin/npm Watchman: 2022.11.14.00 - /usr/local/bin/watchman Managers: CocoaPods: 1.11.3 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: DriverKit 22.1, iOS 16.1, macOS 13.0, tvOS 16.1, watchOS 9.1 Android SDK: Not Found IDEs: Android Studio: Not Found Xcode: 14.1/14B47b - /usr/bin/xcodebuild Languages: Java: 11.0.15 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 17.0.2 => 17.0.2 react-native: 0.68.2 => 0.68.2 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found

Platforms

It's issue with ios platform.

Versions

  • iOS: 16.0
  • react-native-geolocation-service: "^5.3.0-beta.4"
  • react-native-cli: "2.0.1"
  • react-native: "0.68.2"
  • react: "17.0.2"

Description

I am implemented getCurrentlocation API in specific interval and i want to get location data on every 20 seconds so that I store this location in our server. I follow setup file for background fetch. docs/setup.md Here, below I provide a code snippet

  const location interval = async () => {
    locationTimeinterval = setInterval(async () => {
      //for geolocation
      Geolocation.getCurrentPosition(
        async position => {
          console.log('locationcurrentsuccess: ', position);
        },
        error => {
          console.log({error});
        },
        {
          enableHighAccuracy: true,
          timeout: 15000,
          maximumAge: 10000,
        },
      );
    }, 20000);
  };

As per the code, I added getCurrentPosition API in the interval and fetch location data. => This code is working fine in the foreground. => When I move the app to the background, I am not able to get the location.

  • I spend more and more hours resolving this issue but I am not getting any success. I also try watch position API for background tracking but it calls so many time at once so it's not useful for me.

So, my request is that please suggest any solution for this issue.

Thanks in advance.

kikanikishan avatar Dec 27 '22 16:12 kikanikishan

did you solve this?

Sondouni avatar May 16 '23 01:05 Sondouni

No, I tried all possibilities but it's not working at all.

kikanikishan avatar Aug 01 '23 04:08 kikanikishan

Hey, we are also facing this issue. We did have this working at some point but it seemingly stopped working out of the blue. Any ideas? We are thinking of migrating to another lib.

wmonecke avatar Sep 15 '23 13:09 wmonecke

anyone find any solution ?

kikanikishan avatar Jan 24 '24 16:01 kikanikishan

did you guys try expo-location https://docs.expo.dev/versions/latest/sdk/location/#locationstartlocationupdatesasynctaskname-options

I see it supports both foreground and background execution mode for location updates.

Ppang0405 avatar Feb 14 '24 18:02 Ppang0405