Closed jakub-oone closed 1 month ago
Enter/exit geofence is not detected with location permission "Only while app is in use"
That’s correct. Both the iOS and Android geofencing APIs require Always permission.
ACCESS_BACKGROUND_LOCATION
means Always authorization.
If you observe the plug-in logs, you’ll find a ⚠️ message after adding geofences with WhenInUse permission.
OK, but I forgot to mention that we are using GEOFENCE + LOCATION mode in the foreground of the app. iOS works (triggers all geofences) OK with "WhenInUse" permission, so why not Android? Thx.
Consult the Android Geofencing api docs I linked above. The key word is “must”:
Hello @christocracy , you're right that the Geofencing API on Android can't be used without always location permission but the library still has an access to location services (if while in use
permission is granted of course) which were at least previously used to trigger the onGeofence
event on both platforms. This seems to stop working in recent library versions though. We successfully used this behavior in the previous library versions e.g. "react-native-background-geolocation": "4.13.3"
to make geofence-like functionality work on foreground with while in use
location permission on both platforms. After we upgraded to newer version with polygon geofence support (the paid addon) this functionality stopped working on Android (on iOS not).
On the other hand the foreground geofence-like functionality with while in use
location permission works just ok on iOS (even in the demo app) so this looks like a bug on Android which was introduced in some recent library version. Could you please look into this once again?
This seems to stop working in recent library versions though
This is false. You were likely using an older targetSdkVersion. Now that targetSdkVersion >= 33 is required, your app must adhere to these restrictions.
while in use location permission works just ok on iOS
There is no correlation of behaviour between operating systems. They are completely different, created by different companies and implemented with completely different languages.
The Android api docs are clear “To use geofencing, your app must request the following”
Hello @christocracy , thanks for explanation. You're right - the geofencing didn't work even with the previous library version on foreground with only "while in use" permission on Android. We were confused because of specific behavior of the operating system when user grants "always" permission for a while but revokes the permission to "while in use" later. It looks like the Android Geofencing API keeps working on foreground with "while in use" permission if the geofences were added while the app had "always" permission. That's really strange and I can't also understand this Android limitation (geofencing not using on foreground with "while in use" permission) compared to iOS which supports this but that's "as designed" by Google/Android.
We would be super-happy if you would align this behavior on iOS/Android and "simulate" the geofencing on Android on foreground with "while in use" permission using pure location services (we actually thought the library is doing this) but understand you many not be willing to do so. We will need to "simulate" this on our side for now as our app use-cases just requires geo-triggering work on foreground with "while in use" permission only.
If geofencing is crucial to your app, why don’t you instruct your users why it’s important to grant “Always” permission, explaining to them that a certain feature will no longer work if they don’t? If the user insists on granting “WhenInUse”, then perhaps they’re not interested in that feature.
It's quite hard to get "always" permission from normal users because of privacy - we're building SmartGuide travel guide app so that's not a B2B kind of app with limited user base where explaining this would be much easier. It's also technically feasible to perform location-based triggering on foreground with "while in use" permission even though it's not efficient compared to geofencing - general public doesn't even know there's some geofencing API and they just think about GPS.. So we try to explain and get "always" permission but still need to make our core functionality available with "while in use". We already received some 1* reviews because we even try to get the "always" location so we can't push more.. mobile app developer life is not easy :)
Map components often have geometry methods for determining if a location exists within a circle.
Your Environment
react-native -v
): 0.73.0Expected Behavior
Polygon/circle geofence entry/exit is detected and visible on the map in the BGGeolocation demo app. with location permission "Only when the app is in use
Actual Behavior
Polygon/circle geofence entry/exit is not detected and is not visible on the map in the BGGeolocation demo app. with location permission "Only when the app is in use
Steps to Reproduce
Context
Debug logs
Logs
``` PASTE_YOUR_LOGS_HERE ```