-
Notifications
You must be signed in to change notification settings - Fork 424
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 permission manual request not always works #2201
Comments
This option doesn’t do what you think it does. Read about it in the api docs. if you do not want the plug-in to request permission, don’t tell it to .start(). Calling .start() always requests permission. listen to .onProviderChange event to learn about changes in permission. |
No, you probably didn't understand me. Permission request at Steps:
|
The plugin's
Therefore, before calling var providerState = await BackgroundGeolocation.getProviderState();
if (!providerState.enabled) {
// If you find location-services is disabled, you must tell the plugin to .stop(),
// which sets State.enabled -> false
BackgoundGeolocation.stop();
}
.
.
.
BackgroundGeolocation.ready(config) |
It doesn't work as you write. Request still appears at app startup import React, { useCallback, useEffect, useState } from 'react';
import { Button } from 'react-native';
import RNBG from 'react-native-background-geolocation';
export const BugReportExample = () => {
const [enabled, setEnabled] = useState(false);
const onStart = useCallback(() => {
RNBG.start(state => {
setEnabled(state.enabled);
});
}, []);
const onStop = useCallback(() => {
RNBG.stop(state => {
setEnabled(state.enabled);
});
}, []);
useEffect(() => {
RNBG.getProviderState().then(async providerState => {
if (providerState.enabled) {
await RNBG.stop();
}
RNBG.ready({
reset: true,
stopOnTerminate: false,
disableLocationAuthorizationAlert: true,
locationAuthorizationRequest: 'Any',
}).then(state => {
setEnabled(state.enabled);
});
});
}, []);
return (
<Button
title={enabled ? 'Stop' : 'Start'}
onPress={enabled ? onStop : onStart}
/>
);
}; |
That’s not how I wrote it. The plug-in API is asynchronous. You need to |
I'm calling |
Compare your logic: if (providerState.enabled) with mine: if (!providerState.enabled) { if NOT enabled. If location-services are disabled, then .stop(). |
Ah, thx. But permission still requesting 🤷♂️ |
Provider state resolves to {
"accuracyAuthorization": 0,
"enabled": false,
"gps": true,
"network": true,
"status": 0
} I think there is some logic in native code that requests permission |
The plugin only requests permission if the plugin is Are you observing the plugin logs in |
iOS Logs at the app startup with "unexpected" permission request
|
These logs and your simple reproduction app are helpful. I’ll look into it. |
Option
disableLocationAuthorizationAlert
doesn't work as expected. Permission is requested at app startup.Your Environment
react-native -v
): 0.75.3Standalone component to reproduce
Expected Behavior
If some requirement is missed (for proper plug-in work) and I tell that I manually controlling requests (
disableLocationAuthorizationAlert: true
), there should be some warning or error during plug-in preparation (insideready
).Actual Behavior
If location permission is missed (for "permanent" mode), plug-in will request it at app startup.
Steps to Reproduce
Context
I want to request location permission my own no matter the plug-in state is
Debug logs
Logs
The text was updated successfully, but these errors were encountered: