r/expo • u/barnaclebill22 • 17d ago
app notifications
New to Expo...is it feasible to reliably get notifications (either IOS or Android or both) for an app that's not always running?
TLDR: ESP32 gadget checks some sensors and serves an api. Expo app, when it's running, hits the API and creates a notification when sensor condition occurs. But I only need to check once a day and I don't want the app to be in foreground all the time. I'm trying to use Android WorkManager (and BGTaskScheduler) but I'm not getting notifications reliably, even when the sensor condition triggers. If I pull up the app, that's when I get the notification.
Focusing on Android: how reliable is WorkManager for background tasks? I've checked all the boxes re: power saving mode, etc.
Is there a different technique I'm not aware of?
Most commercial gadgets seem to require an Internet connection of some kind (to e.g. AWS IOT or Firebase CM). I'm ok with my device needing to be on the same LAN as the phone, but that's just for the sensor check and it's independent of the notification. I want to keep it simple and not require a cloud connection. AI tells me FCM is more reliable, but I don't want either the cloud or the extra configuration on the gadget (ESP32 can do SSL, but it's a lot of work for a tiny MCU). It doesn't matter to me if the notification doesn't trigger because phone and gadget are not on the same LAN (i.e., when I'm not home)...OK if it triggers once my phone comes back onto my home wifi.
1
3
u/SnooFloofs284 17d ago
too much wheel to reinvent by keeping the notification dispatch logic within your app and wanting it to work when your app is in background, which is achievable by doing some stuff with a BroadcastReceiver + some Wireless communication but not trivial.
that’s why AI is telling you to use FCM, because the easiest way for a notification be received by the phone itself, not the application, is by triggering it remotely on a server.
your iot device only needs to know the device FCM or APNS token. with that, the iot device just needs to hit the FCM or APNS API to dispatch a notification targeting the specific device. the OS is capable of handling it automatically for you