react-native-background-geolocation
react-native-background-geolocation copied to clipboard
Geolocation Stops Working When Resetting Configuration Upon App Restart from Termination
Your Environment
- Plugin version:
- Platform: iOS
- OS version: iPhone 15
- Device manufacturer / model:
- React Native version (
react-native -v): 0.72.3 - Plugin config 4.15.2
const [newConfig, setNewConfig] = useState(false);
// Location Chnage Listner
React.useEffect(() => {
// Register BackgroundGeolocation event-listeners.
var i = 1;
const locationSubscriber = BackgroundGeolocation.onLocation(
async location => {
if (i !== 8) {
console.log(location, i, 'vrrr tracking running');
} else {
console.log(location, i, 'vrrr tracking Completed');
setNewConfig(true);
console.log('seted new config');
}
i++;
},
error => {
console.warn('[onLocation] ERROR: ', error);
},
);
return () => {
// When view is destroyed (or refreshed with dev live-reload),
// Remove BackgroundGeolocation event-listeners.
locationSubscriber.remove();
};
}, []);
// Configure BackgroundGeolocation.ready
const initBackgroundGeolocation = async () => {
// Ready the SDK and fetch the current state.
async function execute() {
await BackgroundGeolocation.ready({
debug: true,
reset: false,
}).then(state => console.log(state));
}
execute();
};
useEffect(() => {
if (newConfig) {
console.log('ddad');
setSchedule();
// initBackgroundGeolocation();
async function stopBGSchedule() {
const state = await BackgroundGeolocation.stopSchedule();
console.log('Oldconfig stop', state);
if (state.enabled) {
await BackgroundGeolocation.stop();
}
}
// e.g `[ '1 00:01-23:59']`
async function setSchedule() {
await stopBGSchedule();
await BackgroundGeolocation.setConfig({
debug: true,
distanceFilter: 25,
stopOnTerminate: false,
startOnBoot: true,
foregroundService: true,
schedule: ['5 09:01-09:20'],
// useSignificantChangesOnly: true,
showsBackgroundLocationIndicator: false,
}).then(state => {
console.log('[setConfig] success: ', state);
});
await BackgroundGeolocation.startSchedule();
}
}
}, [newConfig]);
useEffect(() => {
const sc = [];
cutiee.forEach((item, index) => {
sc.push(buildScheduleString(cutiee[index].cutieeDaycares));
});
setSchedule();
initBackgroundGeolocation();
async function stopBGSchedule() {
const state = await BackgroundGeolocation.stopSchedule();
if (state.enabled) {
await BackgroundGeolocation.stop();
}
}
// e.g `[ '1 00:01-23:59']`
async function setSchedule() {
await stopBGSchedule();
await BackgroundGeolocation.setConfig({
debug: true,
distanceFilter: 25,
stopOnTerminate: false,
startOnBoot: true,
foregroundService: true,
schedule: ['4 09:01-10:50'],
// useSignificantChangesOnly: true,
showsBackgroundLocationIndicator: false,
});
await BackgroundGeolocation.startSchedule();
}
}, []);
Expected Behavior
Schedule Event notification should keep coming after setting new config when using freeway drive
Actual Behavior
Geolocation and Scheduled Event Notifications Stop Working After Resetting Configuration Upon App Restart from Termination
Steps to Reproduce
- run above code
- terminate app
- then start freeway drive
- it will stop giving SLC notification
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.