transistorsoft / react-native-background-geolocation

Sophisticated, battery-conscious background-geolocation with motion-detection
http://shop.transistorsoft.com/pages/react-native-background-geolocation
MIT License
2.54k stars 424 forks source link

Location getting delayed when I add License key to Android app #1977

Open mohankyro22 opened 1 month ago

mohankyro22 commented 1 month ago

Location getting delayed when I add License key to Android app

Is there any way I can overcome the above.

Your Environment

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 ```
christocracy commented 1 month ago

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.

mohankyro22 commented 1 month ago

Will check and update.

mohankyro22 commented 1 month ago

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 ?

christocracy commented 1 month ago

Show me your android/app/build.gradle.

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

mohankyro22 commented 1 month ago

we use as .stage.

mohankyro22 commented 1 month ago

Doesn't the plugin allow that ?

christocracy commented 1 month ago

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.

mohankyro22 commented 1 month ago

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 commented 1 month ago

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

christocracy commented 1 month ago

See API docs Config.disableMotionActivityUpdates.

mohankyro22 commented 1 month ago

Ok thanks.

mohankyro22 commented 1 month ago

LOG_LEVEL_VERBOSE

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

christocracy commented 1 month ago

LOG_LEVEL_VERBOSE

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

mohankyro22 commented 1 month ago

Ok thanks

mohankyro22 commented 1 month ago

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

Manikandan-saminathan commented 1 month ago

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.
mohankyro22 commented 1 month ago
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.

christocracy commented 1 month ago

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

mohankyro22 commented 1 month ago

<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" tools:node="remove" />

So do we have to add this to AndroidManifest file ?

christocracy commented 1 month ago

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
mohankyro22 commented 1 month ago

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 ?

Manikandan-saminathan commented 1 month ago

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 commented 1 month ago

@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" />
     
  2. 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 ?

mohankyro22 commented 1 month ago

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 ?

github-actions[bot] commented 3 days ago

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