Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mohankyro22 opened this issue Mar 25, 2024 · 26 comments
Closed

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

mohankyro22 opened this issue Mar 25, 2024 · 26 comments
Labels

Comments

@mohankyro22
Copy link

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
@christocracy
Copy link
Member

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.

@mohankyro22
Copy link
Author

Will check and update.

@mohankyro22
Copy link
Author

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
Copy link
Member

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

@mohankyro22
Copy link
Author

we use as .stage.

@mohankyro22
Copy link
Author

Doesn't the plugin allow that ?

@christocracy
Copy link
Member

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
Copy link
Author

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
Copy link
Author

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

@christocracy
Copy link
Member

See API docs Config.disableMotionActivityUpdates.

@mohankyro22
Copy link
Author

Ok thanks.

@mohankyro22
Copy link
Author

LOG_LEVEL_VERBOSE

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

@christocracy
Copy link
Member

LOG_LEVEL_VERBOSE

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

@mohankyro22
Copy link
Author

Ok thanks

@mohankyro22
Copy link
Author

mohankyro22 commented Mar 28, 2024

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

@Manikandan-saminathan
Copy link

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
Copy link
Author

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 #1149 (comment)

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
Copy link
Member

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

@mohankyro22
Copy link
Author

So do we have to add this to AndroidManifest file ?

@christocracy
Copy link
Member

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
Copy link
Author

mohankyro22 commented Mar 28, 2024

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
Copy link

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
Copy link

Manikandan-saminathan commented Mar 29, 2024

@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 ?

@mohankyro22
Copy link
Author

mohankyro22 commented Apr 11, 2024

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 ?

Copy link

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

@github-actions github-actions bot added the stale label May 12, 2024
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants