I really need help with this problem, I need to complete this but it was a headache last few weeks.
Problem is I have an app in React Native that needs to find iBeacons even in background. I already got it on iOS but, ironically, on Android is showing a weird behavior. I set it up a Foreground Service with a permanent notification using notifee. So I use a lib to find the iBeacons, but its way to do the job is different in Android or iOS, in iOS just take an array with all the devices in range time to time, so you can do with it what you want. But in Android, it works running a discovery service or whatever and then you set up listeners to enter or exit of the devices.
So, this is the problem: in the dev build, the foreground service looks like still running (log of a tick-tack I did to test shows) but when screens turns off logs of handlers of listeners stop showing, and nothing happens anymore in it. In the preview build, just the notification of the foreground service is the only prove that it exists, even maintaining the phone wake nothing more happens.
I already turned off all the battery optimizations of the mobile phone (Samsung) in both scenarios.
My code looks like this:
notifee.registerForegroundService(async (notification) => {
....//Here I catch the data cointained in notification and start the lib services I test it still working
return new Promise(async () => {
setInterval(async () => {
...// Here I do the test all still working, and set the Listeners to try to resetting them if were drestroy, but still dead.
// The CustomEmitter is a NativeEventEmitter from the lib, it works good on foreground
CustomEmitter.addListener("beaconDidAppear", ({ beacon, region }) => {
console.log("Appears: ", beacon);
beaconEnter(beacon);
});
CustomEmitter.addListener(
"beaconDidDisappear",
({ beacon, region }) => {
console.log("Dissappears: ", beacon);
beaconExit(beacon);
}
);
}, 20000);
});
});
}
If you have any solution or a better approximation to this problem, would be appreciated 🙂
Thank you!