According to this post, the best practice is filtering channel messages on client side. I haven't found a feasible way to do that when push notification is integrated yet. Right now our iOS client gets notified for a lot of useless messages when app is not running.
Filtering PubNub Messages and Push Notifications
This is a shortcoming with APNS, not PubNub. PubNub works in such a way that all subscribers of a channel receive all messages published on that channel. But when an app is in the background on iOS or not running at all, your app does not have the opportunity to process the push notification before it is displayed by the iOS device. Android/GCM does allow your app to intercept the message before it is displayed.
Fortunately, there is only one scenario (that I can think of) where the sender of a msg would receive their push notification version of the message (meaning, you couldn’t intercept and not display it).
user publishes msg
then immediately (quickly) leaves the app (home button, switch to another app, etc)
push msg appears
But if the user stays in the app for a second or two (or long enough to receive the realtime msg AND the push notification), then you can prevent the push msg from being displayed. But there is no need to filter on UUID because you should be suppressing all push notifications from being displayed when the app is active in the didReceiveRemoteNotification delegate, because you already have the realtime message on the subscribe callback.
That link you referenced (Filter Owner Messages on PubNub Data Streams) is only for realtime push notifications and Stephen is calling out a feature that we will be rolling out in the near future which allows you to subscribe to a channel but provide a query that allows you to filter/query condition for the messages on the channel, like, “where uuid != ”, where is the uuid of the subscriber. Then the subscriber would not receive realtime or push notification messages because the server filters them out for you.
For a good overview of push notifications see Sending APNS and GCM Messages to Subscribers and Mobile Push Notification Services in One API Call
For complete push notification setup, configuration and implementation, see the docs for each of our SDKs.
Also, see my answer that describes how to use iOS silent push notifications to do on device filtering. Same thing can be done on Android but no need to do anything special because you always get the opportunity to process the push notification before it is displayed.
Related
For regular single-device push notifications through APNS, less important pushes can "replace" more important ones, because if the device is temporarily offline, only the last notification per device/app is retained and delivered with APNS.
https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/APNSOverview.html#//apple_ref/doc/uid/TP40008194-CH8-SW5
Let's say I'm delivering critical pushes to single devices, and informational, non-critical pushes via a topic-based pushes in Firebase FCM. Would it still be true that the topic-based pushes could replace the critical pushes for an offline device?
A predecessor of mine left behind a design document that said topic-bases push subscriptions would avoid the problem of informational pushes replacing critical ones, but I haven't found any documentation to support that. I'm thinking I might be better off using websockets or similar (maybe via PubNub) for the the informational pushes when the app is in the foreground, and only use APNS/FCM for the critical pushes. Am I right?
disclaimer: this does not directly address the Firebase topic-based aspect of
this question, rather, it provides an alternative solution that has
the same features/implementation for both FCM and APNs with respect to QoS, or more specifically, the ability to retrieve messages that might have been missed while offline.
Publish, Persist & Push with PubNub
PubNub Storage Service
Well, putting APNs and FCM aside, PubNub will persist all of your messages for later retrieval when you enable the Storage service. So when devices are offline, they can receive push notifications (APNs/FCM), and whether or not those notifications are received/acknowledged by the end-user, your app can easily retrieve all messages that were sent while the device was offline.
PubNub Mobile Push Service
The other advantage of using PubNub is that you include the APNs/FCM push payloads in the realtime publish payload and if the device is active/online and subscribed to that channel, then it receives the message in realtime. If the device is not subscribed to the channel, it still receives the FCM/APNs push notification.
NOTE: you must enable the Storage service on your PubNub key set and
configure the retention as required: 1 day, 3 days, ... 30 days or
Unlimited.
I have an existing app that receives push notifications. I've been requested to implement a feature where the user must acknowledge the push notification. If the user does not acknowledge the notification, then they will be alerted again after a set time, until they finally do acknowledge it.
So far, the only solution I've come up with is:
We send a notification from our server to APNS. When the user opens the app after receiving a notification, the app will then send an acknowledgement back to the server. If the server does not receive an acknowledgement from the device within X minutes, it will automatically send another notification.
Is there a better way of implementing this kind of feature, where I'm not relying on sending acknowledgments back to the server?
Create Accept/Reject actions for push notification and save that info on server, so that we can differentiate the accepted ones and others
I was wondering if its possible, using PubNub to route a message as a push notification, even if the app is running in the foreground?
One way that I can think to do this is to:
Handle any specific routing and events that need to happen first.
Check the push note portion of the message and send a local device notification. Alternatively any custom UI, etc could be done here.
PubNub does send the push notification when the app is in the foreground. In fact, PubNub (the mobile push notification server) does not know if the device is foreground, background or not running at all. So the push notification is always sent to the device either way.
See the following PubNub Developer Community article, Sending APNS and GCM Messages to Subscribers and Mobile Push Notification Services in One API Call, for more details.
Also refer to the PubNub iOS Mobile Push Gateway Tutorial for Realtime Apps. These docs are about to get a major upgrade in terms of completeness.
I basically want to make multiple push notifications in the same application visible in the notification tray in iOS.
This scenario works if my data is on while push notification is triggered via APNS, but only the latest one is received in case I am offline and come back after a while. This functionality is affirmed by APNS documentaion.
However, this is what worked in WhatsApp:
Turned Data Connection OFF
Sent some messages to WhatsApp
Turned Data Connection ON
Saw multiple push notifications received in Apple's Notification Tray
How's this scenario working? Can I use APNS for this? If yes, then how?
See this sample image of multiple Push Notifications in WeChat.
Like you wrote in your question, this is mentioned in the Apple Docs:
If you are sending multiple notifications to the same device or
computer within a short period of time, the push service will send
only the last one.
Link
The only scenario that what you're describing will work is if your whatsApp was open in the background while getting those push notifications. That way whatsApp will handle them as local notifications and will present all of them in the notification center. If whatsApp was closed you'd get only the last notification like any other app.
You can easily test this:
Terminate whatsApp and turn on Airplane mode.
Send your device 5 messages from 1 to 5.
Turn Airplane mode off and lock your device.
You'll only see one msg (the last one you sent aka "5") in your notifications center.
This is how whatsApp is making it work:
While whatsApp is in the background, a single push notification is received (the last one the user sent, "5" in our example). That msg will not be shown to the user.
whatsApp receives it in the method application:didReceiveRemoteNotification:fetchCompletionHandler: and checks against their servers if there are any notifications prior to "5" that the user didn't receive. If that's the case, they will pull that data from their servers and will present it to the user using local notifications which is basically just a way to present data and not related to APNS at all.
It is explained in Troubleshooting Push Notifications. Check for "Some Notifications Received, but Not All" section.
As described you cannot have any control over those push notifications.
However you may know that from iOS7 a new background execution mode (remote-notification) allows the App to be awaken by the system when a push is received, allowing you to process some data, then go back to sleep...
This is probably the trick: using that way to receive the push notifications (silently) and then trigger your own local notification instead as #Segev said. See the UIBackgroundModes here.
I am create a firebase based chat application for iOS. One of the features is to send push notification to the users in the same chat room (if they are offline).
I can't find a firebase function (for iOS) that can be used to send push notifications to the user.
Is it possible?
Displaying alert badges and notifications on iPhone applications is accomplished through Apple's Push Notification system. Since the application is not running on the user's phone when they receive notifications, the APN will have to be triggered from your server-side code.
You'll probably want to create a server-side module that listens for changes to your chat Firebase. When a message appears for a user that is offline, you'll have to schedule a remote notification with the APN. That latter part has nothing to do with Firebase, but has extensive documentation on Apple's developer web site.
I'm not sure if a web application can display alerts or badges. Otherwise this approach will only work if you create a native wrapper for your Firebase chat application.