'Push Notifications take too long to arrive
I'm having a weird problem with push notifications in an adobe air app for iOS and Android.
I'm using the Easy Push ANE from Milkman Games along with the One Signal service.
The problem is that notifications do arrive, but sometimes (randomly), it can take up to 15 minutes for the messages to arrive at the device after they are sent.
This is critical for my app (a taxi booking app), since i'm relying on the push notifications for the communication between the taxi app and the users app. So, for example, if a user requests a taxi, it can take up to 15 minutes for the taxi app to be notified.
Talked to One Signal support, and according to them everything is ok on their end, and if I look at the One Signal dashboard, the notifications are delivered almost instantly all the time.
What could be the reason of this delays? and what could i do to make things better?
Thank you.
Solution 1:[1]
Normally push notifications do arrive quite quickly. But there are some rare cases where we've seen them get delayed:
Delays for notifications on Android Devices:
Some home and commercial wifi routers will cause the device's connection to Google's GCM servers to be closed. The device later re-opens the connection and receives the delayed notifications. (Discussed here: https://groups.google.com/forum/#!topic/android-gcm/Y33c9ib54jY)
Some custom versions of the Android OS have a power-saving setting that can cause notifications to be delayed or ignored. For instance, Sony Xperia devices have a "Stamina Mode". (Discussed here: https://talk.sonymobile.com/t5/Xperia-Z3-Compact/Notifications-not-Working-When-Phone-in-Sleep-Mode/td-p/879641)
Some Android devices can enter a low power mode when their battery is low that may cause slight delays in receiving notifications.
Delays for notifications on iOS devices:
When sending notifications to a device build with a development provisioning profile, Apple's APNS servers may sometimes be less fast or reliable. You can compare a version of your app built with an AdHoc provisioning profile and a production push certificate to see if it works better. In the near future, Apple will be changing the way this system works so this problem will go away.
As with Android, some wifi routers will cause iOS notification delivery delays.
Notifications may be delayed if "Restrict background data" is checked for the app, if Wifi-Optimization is turned on in the advanced settings, or if priority mode is enabled.
WhatsApp has a good list of instructions on troubleshooting delayed Android and iOS notification at the bottom of their FAQ page here: https://www.whatsapp.com/faq/en/android/20887936
Overall, the above problems are rare and almost all users will receive notifications promptly. However for your specific use case you may find Text Messages to be a more reliable tool.
Solution 2:[2]
I was also dealing with delayed notifications in most of the apps in my phone. Finally after long searching on the Internet and trying common advices as a disabling battery optimizations, Adaptive Notifications and all those features that didn't help at all, I found the XDA Developers forum where I finally got to the bottom of this issue.
This problem is caused by functionality called as "DOZE", which is implemented in the Android core since Android 6.
https://developer.android.com/training/monitoring-device-state/doze-standby
Basically what is does is that it tries to preserve the phone battery life in a very aggressive way that basically puts all applications and network activity to standby until the maintenance window occurs. The maintenance window is a very short time period where all events from applications waiting in the queue are processed at once and then it puts all apps to standby again until next maintenance window occurs.
Problem is that with every next maintenance window the intervals between those windows are increasing every time up to some long limit. So if you haven't touched your phone for a longer time, like half an hour and the event happens, you will get the notification in the next maintenance window that may be tens of minutes from that moment.
I don't know how Google can act as this is OK. It is NOT!! For me it was causing serious problems with my Forex trading app that didn't display price alerts on time when the event happened but like 5, 15, 30 minutes or even almost 1 hour later !! which is not useful for me because the opportunity for the trade was already gone...
So solution is to disable the "DOZE" in your phone manually using ADB commands. I did it and it works, now I get instant notifications. Unfortunately this has to be done every time after phone reboot as it turns itself the DOZE back on again.
Here is a page with more details:
Android: completely disabling deviceidle ("Doze") in Android M?
Basically you just issue this ADB command: dumpsys deviceidle disable
You can also put the application to the Doze whitelist but not sure if it works, when I displayed the list, I found out my trading app was already there, maybe because I removed it from the Battery saving policy but the Doze was probably still suspending everything so it worked only in those maintenance windows. I guess it doesn't use those "high-priority FCM messages" described in the DOZE description to force the notifications instantly.
If you are not familiar with ADB, here is some info:
https://developer.android.com/studio/command-line/adb
I used a paid app that allows local ADB connection from the phone directly, so I can disable DOZE after every restart. More info here:
It is very sad that this basic feature as an instant notifications have to be fixed via the developer debug interface by user instead of Google who could fix it in the OS itself...shame on Google...
More forums on this topic:
https://forum.xda-developers.com/t/delayed-notification-problems-s21-ultra.4243105/page-5
Solution 3:[3]
In my case, in the payload that I send to APNS, I was sending "attachment" property as "". When I changed it to null, the problem gone away.
Replace
"attachment": ""
with
"attachment": null
I don't know why, but oddly it was causing the notification to go as late as 1.5 minutes or something.
Solution 4:[4]
Really hope Android OS will improve push notification delays. Sometimes it doesnt get notification for an hour if you dont touch the screen. It may be good for some users due to battery saving but optimising push notification along with battery optimisation can be win win for everyone.
Anyway, here are a few little tips for those who want to analyse dozing stuff and those not aware of these already:
Wireless debugging feature can be used to connect device with computer/adb tools. So no need a usb cable and charging the phone while connected doing tests. I think since Android 11 most devices has wireless debugging option under developer options, this works natively without a usb cable setup. If no wifi debugging available(Android versions before 11) then usb cable can be used to setup it.
"adb shell dumpsys deviceidle" this command summarize some info like status of doze and sub states, can be used to check current status during doze/app testings.
You can check other adb doze commands and their effects like forcing doze, enable/disable it etc. online.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Tomcat2 |
Solution 3 | Burak |
Solution 4 |