Sometimes, when our app does not have permission to access Location Services, it gets into a state where the locationAuthorizationAlert pops up continuously, completely blocking usage of the app. Going into Settings and granting the app the correct permissions has no effect, it just keeps creating more alerts. Swiping away and restarting the app is the only solution.
We have not narrowed down exactly the conditions required to reproduce this, but it seems to happen when the app is running in the background for long periods of time (e.g. overnight) without the right permissions. Any ideas for what could be causing this? Is there some way to just disable those alerts for now?
react-native -v): 0.39.1 // Geolocation Config
license: 'our-license',
desiredAccuracy: 0,
stationaryRadius: 25,
distanceFilter: 10,
// Activity Recognition
stopTimeout: 60,
stopDetectionDelay: 60,
locationUpdateInterval: 1000,
// Application config
stopOnTerminate: true,
startOnBoot: false,
maxRecordsToPersist: 1,
url: queuePostURL,
autoSync: false,
When the app doesn't have the correct permissions, it should pop up the locationAuthorizationAlert once.
The alert pops up, but pressing Cancel spawns a new one. Pressing Settings opens up the Settings app correctly, but then another alert is spawned as soon as we switch back to our app. This repeats until we restart the app.
Show me what other plugins you have installed in package.json
Also show me your Info.plist
Here are the other relevant react-native dependencies we have in our project.
(redacted)
Info.plist
(redacted)
Tell me how to reproduce this issue.
We haven't been able to come up with a surefire way to reproduce it. But this generally seems to cause it: turn on Location Services, grant app "Never" permission to use it. Start up app, then leave running in the background for a long period of time (overnight). Open app again, immediately see endless alerts. We've only seen it occur on iOS 10.
Is there a way we can just turn off the alerts through your API?
I think I've got a solution for this from the Cordova side. I'm just waiting for feedback. I'll post a new version of TSLocationManager.framework here once it's confirmed.
Ok, this is fixed in the premium repo. Have you not migrated to using the premium repo for both iOS and Android?
Thanks for the fix. I see that it is on top of the RN 0.40 breaking change for iOS. We're planning to upgrade to 0.40 in the next week, so I will let you know if we're still seeing this issue as soon as we do that.
Try branch 2.3.0-dev. I back-ported it.
@christocracy I'm running into the issue too, currently on 1.6.0. I went looking for your 2.3.0-dev patch but couldn't see it.
I take it from the discussion above the fix ended up in 2.4.0? As I understand it, it'd require me to be on RN 0.40 for 2.4.0 to be compatible? If so, for various reasons I can't upgrade RN just yet.
Is there anyway to disable the alert entirely (from 1.6.0)? Or is it a constraint with iOS?
P.S. I also noticed https://github.com/transistorsoft/react-native-background-geolocation/blob/1.6.0/docs/README.md#param-string-locationauthorizationrequest-always has been removed from the API docs since 2.3.0. But clearly it's still a feature, what's going on there?
Thanks, and sorry if I'm hijacking the thread slightly.
I posted the fix the the Premium Version only so far (the referenced branch exists there), where I'm waiting for feedback. Latest updates are only available in the premium version.
It used to be that the premium version contained only the Android version, but I've since merged iOS there now as well.
As for disabling the alert, no. If you don't want the alert to appear, don't ask the plugin to fetch a location. Listen to the providerchange event, for example:
bgGeo.on('providerchange', function(provider) {
if (provider.enabled) {
bgGeo.start();
} else {
bgGeo.stop(); // <-- When location-services are disabled, turn off the plugin.
}
});
The free version here contain only the latest stable release.
I was not aware of the missing locationAuthorizationAlert. That's a bug. If you need those docs now, you can reference them in the Cordova Version (the docs are identical).
@christocracy Thanks for the reply.
Ah, that's a nice idea. However, the alert still occurs when switching between "Always" and "WhenInUse" permission. Not just when the location service is completely disabled.
For example, when configuring locationAuthorizationRequest to "Always", then switching the option in the iOS settings to "While Using the App", opening the app back up, the alert appears.
I don't actually mind whether users choose to have it always on or just while their using the app, but I guess that is the expected behaviour to show the alert if the permission you requested doesn't match what the user has set.
I just tried a little experiment using the providerchange method (this won't work in the Free version yet). Here I dynamically change the locationAuthorizationRequest to match what the user desires.
BackgroundGeolocation.on('providerchange', function(event) {
console.log('- providerchange: ', event);
if (event.status === BackgroundGeolocation.AUTHORIZATION_STATUS_ALWAYS) {
BackgroundGeolocation.setConfig({
locationAuthorizationRequest: 'Always'
});
BackgroundGeolocation.start();
} else if (event.status === BackgroundGeolocation.AUTHORIZATION_STATUS_WHEN_IN_USE) {
BackgroundGeolocation.setConfig({
locationAuthorizationRequest: 'WhenInUse'
});
BackgroundGeolocation.start();
} else {
BackgroundGeolocation.stop();
}
});
@christocracy Oh, brilliant. Thanks so much for going out your way to demonstrate that. Now that the iOS is available via a premium, I'll see if we can get onboard with it. Thanks again.
I've fixed the docs in master, adding the missing locationAuthorizationAlert, locationAuthorizationRequest.
https://github.com/transistorsoft/react-native-background-geolocation/tree/master/docs#param-object-locationauthorizationalert
@nouveller I've added these changes I mentioned above to the free version and released as 2.3.1 (and 2.4.1 for those using react-native 0.40.0+) on npm.
@christocracy You sir are a true gentleman, my project manager is currently singing your high praises.
@nouveller The free version doesn't normally get updated as frequently as I am now. Latest updates always go to the Premium Version first and this Free version gets the latest stable release only, typically lagging by a couple of months. I'm making an exception for the short term, to deal with the breaking changes introduced by React Native in 0.40.0.
Can confirm that the 2.3.0-dev branch does indeed fix this issue. We will be upgrading to the latest version on the premium repo this week sometime. Thanks again for the fix.
Most helpful comment
I've fixed the docs in master, adding the missing
locationAuthorizationAlert,locationAuthorizationRequest.https://github.com/transistorsoft/react-native-background-geolocation/tree/master/docs#param-object-locationauthorizationalert