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

Location getting delayed when I add License key to Android app

Open mohankyro22 opened this issue 1 year ago • 25 comments

Location getting delayed when I add License key to Android app

Is there any way I can overcome the above.

Your Environment

  • Platform: iOS or Android: Android
  • OS version:
  • Device manufacturer / model:
  • React Native version (react-native -v): 0.70.6
  • Plugin config
    useEffect(() => {
        BackgroundGeolocation.ready({
          desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
          distanceFilter: 10,
          stopTimeout: 1000,
          debug: false,
          logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
          stopOnTerminate: false,
          startOnBoot: true,
        })
      }, [])

    const fetchCurrentLocation = async () => {
      try {
        BackgroundGeolocation.start()
        setIsLoading(true)
        await BackgroundGeolocation.getCurrentPosition({
          persist: true,
          samples: 2,
          timeout: 1000,
          maximumAge: 10000,
          extras: {
            getCurrentPosition: true,
          },
          desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
        }).then((location: Location) => {
          const { longitude, latitude, altitude, accuracy } = location.coords
          const locationDetails = {
            longitude,
            latitude,
            altitude,
            accuracy,
            timestamp: new Date(),
          }
    
          if (setFieldValue && fieldName) {
            setFieldValue(fieldName, JSON.stringify(locationDetails))
            setIsLoading(false)
          }
        }).catch((err) => {
          console.error('Location fetching Inner Catch Error', err)
        })
      } catch (error) {
        console.warn('[getCurrentPosition] error: ', error)
        // Handle error appropriately (e.g., show error message)
      } finally {
        BackgroundGeolocation.stop()
      }
    }

Expected Behavior

To get location quicker when license key is added.

Actual Behavior

Significantly there is delay in getting the current location when I added the License key to the Android App. Before adding the License key it was about 2 or 3 seconds to get the currentLocation but after adding License key it is taking about 10 seconds.

Debug logs

Logs
PASTE_YOUR_LOGS_HERE

mohankyro22 avatar Mar 25 '24 21:03 mohankyro22

there is delay in getting the current location when I added the License key to the Android App.

It can only be a coincidence. Adding the license key cannot possibly affect the time retrieving a location.

  • Set debug: true.
  • Observe the logs with $ adb logcat *:S TSLocationManager:V.
  • Go outside to test. GPS only works outdoors.

christocracy avatar Mar 25 '24 21:03 christocracy

Will check and update.

mohankyro22 avatar Mar 25 '24 21:03 mohankyro22

Hey @christocracy,

I got a question.

We use 3 different env's for our RN application. When I add the License key to AndroidManifest main file.

The key validation failure message is not been shown on dev and prod but showing up on the stage.

Is there anything on it ?

mohankyro22 avatar Mar 26 '24 12:03 mohankyro22

Show me your android/app/build.gradle.

The plugin allows a finite number of suffixes to unlock the plugin for other variants:

  • .dev / .development
  • .staging
  • .qa
  • .uat
  • .test

christocracy avatar Mar 26 '24 13:03 christocracy

we use as .stage.

mohankyro22 avatar Mar 26 '24 13:03 mohankyro22

Doesn't the plugin allow that ?

mohankyro22 avatar Mar 26 '24 13:03 mohankyro22

Doesn't the plugin allow that ?

No. The only known suffixes are listed above. The plugin is not aware of the suffix .stage. Rename yours to .staging and it will work.

christocracy avatar Mar 26 '24 13:03 christocracy

Ok thanks.

image

For now we are only using getCurrentPosition. Is the above alert will mandatorily show. Is there a way to disable this.

mohankyro22 avatar Mar 27 '24 13:03 mohankyro22

We aren't making use of background location fetching as of now.

mohankyro22 avatar Mar 27 '24 13:03 mohankyro22

See API docs Config.disableMotionActivityUpdates.

christocracy avatar Mar 27 '24 13:03 christocracy

Ok thanks.

mohankyro22 avatar Mar 27 '24 17:03 mohankyro22

LOG_LEVEL_VERBOSE

Do we have to use this in the config ? Can this be removed ?

mohankyro22 avatar Mar 27 '24 17:03 mohankyro22

LOG_LEVEL_VERBOSE

This is for developer debugging and testing only. Released app should have LOG_LEVEL_NONE

christocracy avatar Mar 27 '24 17:03 christocracy

Ok thanks

mohankyro22 avatar Mar 27 '24 18:03 mohankyro22

If we disable using Config.disableMotionActivityUpdates as true. We need not mention NSMotionUsageDescription in the info.plist ?

mohankyro22 avatar Mar 28 '24 04:03 mohankyro22

we are getting an app rejection with following message:

ITMS-90683: Missing purpose string in Info.plist. 
Your app’s code references one or more APIs that access sensitive user 
data, or the app has one or more entitlements that permit such access. 
The Info.plist file for the "{app-bundle-path}" bundle should contain a 
NSLocationWhenInUseUsageDescription key with a user-facing purpose string 
explaining clearly and completely why your app needs the data.
If you’re using external libraries or SDKs, they may reference APIs that 
require a purposeful string. While your app might not use these APIs, a 
purpose string is still required. For details, visit: 
https://developer.apple.com/documentation/uikit/protecting_the_user_s_privacy/requesting_access_to_protected_resources.

Manikandan-saminathan avatar Mar 28 '24 04:03 Manikandan-saminathan

Screenshot 2024-03-28 at 6 13 06 PM We are getting like this when app is submitted for play store.

As per the your docs on Android Manifest file we have to add the License key alone right ?

But on this https://github.com/transistorsoft/react-native-background-geolocation/issues/1149#issuecomment-726295227

I could see some of ACCESS_BACKGROUND_LOCATION permission and all.

We are only using current position request as of now.

@christocracy will be happy to hear from you asap.

mohankyro22 avatar Mar 28 '24 13:03 mohankyro22

See my blog about this. Pay particular attention to the final paragraph, showing you how to manually remove a requested permission.

christocracy avatar Mar 28 '24 14:03 christocracy

So do we have to add this to AndroidManifest file ?

mohankyro22 avatar Mar 28 '24 14:03 mohankyro22

So do we have to add this to AndroidManifest file ?

That is exactly what is says, no?

Screenshot 2024-03-28 at 10 15 01 AM

christocracy avatar Mar 28 '24 14:03 christocracy

image

We are seeing this on the Play store submission.

Do we have to set,

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

or

<uses-permission android:name="android.permission.FOREGROUND_SERVICE_HEALTH" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />

@christocracy ?

mohankyro22 avatar Mar 28 '24 17:03 mohankyro22

image

We are seeing this on the Play store submission.

Do we have to set,

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

or

<uses-permission android:name="android.permission.FOREGROUND_SERVICE_HEALTH" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />

@christocracy ?

Any update on this @christocracy

Manikandan-saminathan avatar Mar 29 '24 03:03 Manikandan-saminathan

@christocracy

When the application target SDK was set, 34 faced this. I tried two approaches . Because android newly announced Required the foreground service types

  1. I was also removed from the below permission using tools:node="remove" option
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_HEALTH" tools:node="remove" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" tools:node="remove" />
  
  1. Downgrade the SDK version to 33

I am using this library to get the current location only with the following config

await BackgroundGeolocation.getCurrentPosition(
        {
          persist: true,
          samples: 3,
          timeout: 30,
          maximumAge: 5000,
          extras: {
            getCurrentPosition: true,
          },
        },
        (location) => {
          const { longitude, latitude, altitude, accuracy } = location.coords
          const locationDetails = {
            longitude,
            latitude,
            altitude,
            accuracy,
            timestamp: new Date(),
          }

          if (setFieldValue && fieldName) {
            setFieldValue(fieldName, JSON.stringify(locationDetails))
            setIsLoading(false)
          }
        },
        (failure) => {
          if (setFieldValue && fieldName) {
            setFieldValue(
              fieldName,
              JSON.stringify({
                longitude: '',
                latitude: '',
                altitude: '',
                accuracy: '',
                timestamp: '',
              }),
            )
          }
          console.log('🚀 ~ fetchCurrentLocation ~ failure:', failure)
        },
      )
      ```

I followed the first approach (removing the permission from the manifest). Is that the correct way to approach ?

Manikandan-saminathan avatar Mar 29 '24 07:03 Manikandan-saminathan

Do we have to execute

useEffect(() => {
    BackgroundGeolocation.ready({
      desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
      locationAuthorizationRequest: 'WhenInUse',
      disableMotionActivityUpdates: true,
    })
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [])

this on all the screens wherever the location is being fetched ? @christocracy ?

mohankyro22 avatar Apr 11 '24 09:04 mohankyro22

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar May 12 '24 01:05 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar May 26 '24 01:05 github-actions[bot]