I am working on my first Windows UWP app. And planning use Windows push notifications to notify the app about some server updates. This app will not have internet access always. It might be offline for couple of days. So I wanted to make sure whether I can use Push notifications in such a situation. When the notification is sent from the server if that device is offline, how long it will be there without being removed from the queue?
In a article I have read "By default, push notifications expire three days from the time that they are received by Windows Push Notification Services (WNS). If needed, you can override this default with an explicit expiration time." But I am not sure whether this is referring to what I am asking or whether it's saying that when it's delivered to the device, the tile, badge etc will remove that after 3 days.
Can you please clarify this.
By default, push notifications expire three days from the time that they are received by Windows Push Notification Services (WNS). If needed, you can override this default with an explicit expiration time.
I'm not sure where you've read this. However, this is not quite right. The three days expiration time refers to the lifespan of tile and badge notifications when they have been delivered by the device. It does not start from the time that they are received by WNS.
By default, local tile and badge notifications don't expire, while push, periodic, and scheduled notifications expire after three days. So in Expiration of tile and badge notifications, it says
By default, tile and badge notifications expire three days after being downloaded.
And we can change the expiration time for each notification by setting the X-WNS-TTL header. This header is uaually used if you want to ensure that your notifications are not displayed later than a certain time. The TTL is specified in seconds and is relative to the time that WNS receives the request.
For your question, from the Important notes under Sending a notification in Windows Push Notification Services (WNS) overview, we can find that:
When the device is offline, by default WNS will store up to five tile notifications (if queuing is enabled; otherwise, one tile notification) and one badge notification for each channel URI, and no raw notifications. This default caching behavior can be changed through the X-WNS-Cache-Policy header. Note that toast notifications are never stored when the device is offline.
And in X-WNS-Cache-Policy header, we can get more information.
When the notification target device is offline, WNS will cache one badge and one tile notification per app. If notification cycling is enabled for the app, WNS will cache up to five tile notifications. By default, raw notifications are not cached, but if raw notification caching is enabled, one raw notification is cached. Items are not held in the cache indefinitely and will be dropped after a reasonable period of time. Otherwise, the cached content is delivered when the device next comes online.
So when your app is offline, WNS can cache some push notifications for you, but it's hard to say how long they will be cached.
WNS responds to indicate that the notification has been received and will be delivered at the next available opportunity. However, WNS does not provide end-to-end confirmation that your notification has been received by the device or application.
WNS does not guarantee the reliability or latency of a notification. If you want to make sure users can be notified about the server updates, you may need to use some other techniques. For example, you can send an active request to the server for the server updates when the app is online.
Related
I've been working in bulk web push notifications, migrating from OneSignal to Firebase. I've created a single FCM topic to which all users are subscribed immediately on startup.
At first messages arrive on the browser and the notification is shown correctly, but randomly after a few hours and in some devices, notifications cease to show. I've been recording every push message received using DevTools, and noticed that the messages are being received but the push event not dispatched in those cases.
In which cases something like this may happen? It's worth noting that the service worker has been healthly with no errors whatsoever.
Thanks
I make web app for restaurants. when client in restaurant on web page selects dishes, he clicks "order", and waiter will receive a push notificarion on his phone via fcm for web. Will waiter receive all notifications through fcm for web? I need them to be delivered in 2 minutes maximum, can firebase fulfill my requirements? Thank you
Realistically, most messages will be delivered in under a few seconds, assuming the target device is active and has a good network connection. In practice, there is no way to ensure the timing of the delivery of a message, as the network could be poor or missing, and the device could be in a battery-saving state the delays receipt. If you want to increase the chances of the message getting to the device, use a high priority notification, as described in the documentation.
I'm having trouble figuring out how FCM behaves when I send a notification to an iOS device that is offline (e.g. in airplane mode, or turned off).
The documentation on the time_to_live property mentions that Currently, time_to_live is not supported for notification messages on iOS. but doesn't provide an explanation of what is done instead. I've tried testing it, and it seems like a push notification sometimes goes through, and sometimes does not, regardless of what I set the time_to_live property to be, although I'm not sure if that's due to throttling or something else happening on the FCM side.
Relatedly, I can't seem to get the delay_while_idle property to work on iOS, although the documentation does not explicitly mention that it isn't available for iOS - notifications that are sent while the phone is asleep still wake the phone, even if I set delay_while_idle to be true.
Does anyone have any insight into how this is supposed to work?
The time_to_live is AFAIK applicable to both Android and iOS. However, since the process of sending the message to iOS devices for FCM goes like this:
App Server > FCM Server > APNs > iOS device
It is safe to say that only the FCM Server makes use of the time_to_live, as per it's description:
This parameter specifies how long (in seconds) the message should be kept in FCM storage if the device is offline. The maximum time to live supported is 4 weeks, and the default value is 4 weeks. For more information, see Setting the lifespan of a message.
Looking around, the behavior for APNs when sending to offline devices is (from the Apple docs):
Apple Push Notification service includes a Quality of Service (QoS) component that performs a store-and-forward function. If APNs attempts to deliver a notification and the destination device is offline, APNs stores the notification for a limited period of time and delivers it when the device becomes available again. This component stores only the most recent notification per device and per app. If a device is offline, sending a notification request targeting that device causes the previous request to be discarded. If a device remains offline for a long time, all its stored notifications in APNs are discarded.
As of now, delay_while_idle is now deprecated.
The way I know that you could do to wake up an iOS phone (online/connected to a decent network) is to simply set the priority to high.
The idea of using the push notifications is only to have a notification mechanism that will send a notification when there is a new message waiting to download from the backend service: all the notifications are of the same type e.g. "refresh messages from the server" (the same for Android and iOS).
Are there any limits for the Apple/Google push notifications services?
Assuming that my application will handle more that 100k active users (or even 1M or more users) - would there be any problem with the Apple Push Notifications or GCM services?
If using the push notifications for such a service is not a good idea then what is other solution that could be used for mobile chat applications?
Don't forget that on iOS user may forbid sending notifications, so your app won't receive any even in foreground. Thus, you need to implement your own push mechanism.
Need for push notifications
Especially on iOS you don't have a choice but to use their push notifications service APNS. There is no other way to receive notifications immediately because iOS may kill or neglect the TCP connections of your background app.
On Android it seems possible to use your own background TCP connection to avoid having to use push notifications. But you may still consider the use of the push notifications through GCM for the sake of improved battery usage.
Pricing
Neither APNS (iOS) nor GCM (Android) charge you for the service and you are allowed to send an unlimited number of messages.
Limitations and Requirements
Both services will delete message, when there are too many messages accumulated in the queue for an offline device - which makes sense because there is no point in delivering those messages hours later. You have to take that in to account, when writing your app (just do a poll when going back online).
Depending on the app you are writing, there may also be privacy concerns. Even if you encrypt the message itself, at least Apple/Google know when a notification is sent to a certain device, which may be a deal-breaker for certain high-security applications.
You will also need a server that is able to communicate to both APNS and GCM. There are open source solutions for that (e.g. easyApns for iOS and python-gcm for Android), but how easy their integration is depends on your server and the language it is written in.
I'm trying to understand what I will need to build on my server for Push notifications to work successfully.
My thoughts were:
The phone sends the notify URL to my server
The server stores the information in a Database
A separate process or PHP script will query the database and open continuous looping process for each device. (Each socket will be querying a 3rd party API)
When there is a change detected in the API for that device a push notification will be sent to the device's notify url.
Is this the right method on what needs to be done. Isn't this going to eat up server resources or is it the expected outcome of Push a push notifications server?
I've produced a simple diagram on all this below:
First of all, let's separate the process in the main stages needed for PUSH.
Device subscription.
Send the PUSH
Process the notification on device.
Subscription
For the subscription, your device (more specifically, your App) must call the PUSH api,for enabling PUSH notifications. This call to the push API will give you a URL that uniquely identify the device where your application is installed and running. You should store this URL on your database, the same way you store a user's email, or a user's phone number. No special black magic here. You only use it when you need to send a communication to a user.
Send the PUSH
For the push stuff, the same approach as for email, or SMS messaging here: "One does not simply make an infinite loop and send a message if any change is detected". What you have to do is, just send the PUSH message when your application needs to. So you have the user to which you want to send a message, instead of opening a SMTP connection to send ane mail, just build the PUSH XML Message and call the URL associated with that user. Some things to consider here are:
Network reliability (you need to retry if you can't connect to the server).
Response error code-handling (you don't need to retry if the server tells you that the phone has uninstalled your application, for example).
Scalability. You don't want to send a PUSH message from your PHP code, because you don't know how long it will take for the task to be completed. You have to make this thing asynchronously. So just queue up all the push messages, you can create a separate process (windows service, nodeJS service, cron job, daemon, etc.) to send the PUSH, handle retries and errors and clean the queue.
Process the notification on Device
So now that you are this far, you need to handle the notification on the phone. It depends on the type of PUSH notification that you are sending:
Tile. You will update the image, text and counter of the application tile, if the user has put your application to the start screen. On client side you need nothing to so, as all these parameters are part of your PUSH request.
Toast. This one requires a title, text (limited to some 35 characters more or less) and a relative URL inside of your APP. Your application will be launched (like when you click on a Toast notification from Twitter, for example) using the URI that you specify in the payload. So a bit of data can be already injected here. You may/or may not make a request to your server for new data. It is up to you.
Raw. This one is pretty much silent. Is not seen by the user if your APP is not running. As you might guess, this kind of PUSH is useful to live update your running APP, instead of continuously polling your server, wasting user battery and bandwidth and wasting your server resources. You can send anything (raw bytes or strings) up to the max size of the payload allowed my Microsoft.
If yo have any more questions, don't hesitate to ask.
Bottom line: separate the PUSH sending, make it async, don't you ever forget that...
Your PHP script that continually pings the database for changes...THAT is what will eat up your system resources. Push notifications go hand in hand with Event Driven Programming. This means that ideally, your code shouldn't continuously ping your DB. Rather, when something happens (ie, an "event"), THEN your code does something...like contact your phone via push notification.
Your steps for push notifications are more or less correct, but are incomplete. Step 4: the server contacts the client via the notify url (which you have). Step 5 is that the client then contacts the server to actually pull down the information it needs. That is: The new information is not provided to the client via the notify url. Once the client has its new information, then the program continues as normal (populates a list, downloads skynet, etc.)
Your third step is very wasteful and not practical if your app is installed on more than a few devices.
Instead, each device should be subscribed to types of server updates it cares about. Your server's DB will have a mapping from each type of update you support to the list of notification channel URLs of devices that care about this update type.
When your server detects an update of type X, it would send a notification to all devices subscribed to that type of update.