What is a mobile push notification?
A mobile push notification is a message typically sent from a server to a device that instructs mobile applications (iOS and Android) and browsers to perform some action. Push notifications can deliver information to users on their devices when the application is in the foreground, background, or even closed.
PubNub offers mobile push notifications service with event trigger or state-based alerts that bring your users back to games, stores, classes, and more. You can keep your customers informed with real time alerts, highlight exceptions, or update statuses.
How do Push Notifications fit in with PubNub?
Push notifications normally work by having your application register user devices. A service provider such as Apple Push Notification service (APNs) for iOS devices and Firebase Cloud Messaging (FCM) for Android devices will then deliver messages to these registered or certified devices that use your application. To be able to use these service providers in your application to deliver push notifications, you would have to integrate each framework into your application. This means that you’ll need to include the extra libraries, SDKs, and code handling for each type of device that you want to send push notifications.
However, PubNub supports push notifications with the same SDK that you normally use to integrate your application with PubNub’s real time messaging. Since the application has already registered the device, you need to provide the push registration token and format the message payload, which contains a reserved section for push notifications. You can then add your iOS, Android, and web notifications in one call, without needing to depend on the frameworks and libraries of the other services - all you need to do is include information in the payload, and let PubNub handle the rest.
PubNub can perform this action by acting as a bridge between your application and the service. This feature is called PubNub’s Mobile Push Gateway.
PubNub’s Mobile Push Gateway
When PubNub’s Mobile Push Gateway is enabled, you may associate unique mobile device tokens to PubNub channel names. Once this association is made and when a message is published to a channel, all associated devices will receive that message via their associated FCM or APNs providers. Behind the scenes, the PubNub Mobile Push Gateway establishes an authenticated connection to the push providers based on your registered configuration.
Mobile push notifications are delivered in the following manner:
The application publishes to PubNub via a channel that has a device registered to receive mobile push notifications with the push payload.
PubNub inspects the payload. If a specific mobile payload is found, it checks for device registrations on the channel. If found, PubNub forwards the push to that service provider (FCM/APNs).
FCM/APNs providers then deliver the mobile push notification to one or more devices.
PubNub doesn't directly deliver push notifications to devices. Instead, we forward them to the service provider if the mobile payload is identified and the device is registered on that channel.
So why use PubNub if we rely on service providers for push notifications? PubNub simplifies the process by allowing you to send push notifications to multiple device types (APNs or GCM) with a single function call. This eliminates the need to integrate with different SDKs or make multiple calls to various service providers, as the same payload used for in-app messaging can handle it all.
Mobile Push Notifications and PubNub’s Real time Messaging
You might be asking yourself: “Why wouldn’t I just use mobile push notifications for messaging instead of in-app messaging if I need to always be connected to the internet and won’t work if the app is in the background or closed?” You certainly could do it this way. However, there are severe limitations for the type/size of the push notification, high-latency/delivery, and user settings: your users would have a poor and frustrating experience.
Size and Types of Messages
Mobile push notifications are meant to be fairly small in size. Both FCM and APNs are based on the XMPP protocol, which means that the message types are XML-based and generally heavyweight. FCM message sizes are restricted to 4KB and APNs message sizes are restricted to 2KB in size. This means that you have to be careful with exceeding the maximum size for the payload. PubNub supports messages up to 32KB in size, and can deliver varying message types, including text, images, and emojis.
High Latency and Delivery
As mentioned earlier, FCM and APNs are based on the XMPP protocol. While a powerful protocol for real time communication platforms, these service providers can take a long time to deliver these push notifications, as it depends on their services. FCM will throttle your messages, limiting the speed and amount of messages your users can receive. Suppose the device that is the intended recipient of a push notification is unreachable by the push service within the expiry window for the push notification. In that case, the push notification will be lost or silently consumed. Push notification networks also generally cannot acknowledge that the push notification was successfully received on the device (no bi-directional communication). PubNub’s communication platform is fast and reliable, and missed messages on the PubNub Network can be retrieved using PubNub’s Message Persistence Feature, and can thus be successfully received by the recipient.
User Settings
Even if the service provider can deliver the mobile push notification on time, many push notifications may never even reach the intended users. This may not be the fault of the service providers; it can be caused due to user settings. Users can choose to place notifications in silent mode or even opt-out of push notifications. This means that they won’t see or even be properly notified of these push notifications. While there are companies like Airship and Netcore that provide services to help increase the success rate of push notifications, they can still be denied based on user settings.
Due to these issues, PubNub uses mobile push notifications as a fall-back mechanism: push notifications can then be used to notify users about news, updates, or messages in the background or when the app is closed, even if there is no direct PubNub connection. Using both real time messaging and push notifications on the PubNub Network means that you can take advantage of low-latency and reliable in-app messaging, and any missed notifications can be retrieved at a later time.
Setting up Mobile Push Notifications with PubNub
Normally, the first step to use mobile push notifications is to get set up with the various notification services. To do this, developers register their app with the necessary push notification services for their target platforms. They ensure that user devices that install their app also register with that service to receive notifications. Then, it’s just a matter of sending the notifications, which has two parts: getting the information that will go into your notification, then sending the notification itself to the desired endpoint, whether it’s a desktop device, browser, or mobile app.
PubNub simplifies this process into a single, seamless activity, and makes it easy to automatically align your in-app and push activity. With our solutions for mobile push notifications, you don’t need to develop push notifications separately from in-app alerts or activity. Instead, our easy-to-use APIs let you automatically trigger push notifications from real time messages for offline users, or have simply put your app in the background.
With PubNub, it’s easy to get mobile push notifications up and running in your app. Our in-depth documentation walks you through each step, but we’ll summarize the simple process right here:
Register your app with APNs for iOS devices and FCM for Android Devices.
Enable the mobile push gateway feature for your app in the PubNub Admin Portal and upload your GCM API Key and/or the APNS Certification.
When users install your app, register that device with its respective push notification provider and obtain a device token for that device from APNs or FCM.
In the client-side application code using that SDK, register the device with specific PubNub channels using the device token.
Implement code to receive push notifications.
Send your push notifications by formatting the payload to meet the needs of your targeted platforms:
After you send your message, let PubNub handle the rest! PubNub lets you define the contents of your push notification right alongside your real time messages, so you don’t have to spend additional development time just to set up alerts, and you don’t have to worry about keeping them in sync and accurate to in-app activity. Instead, with a single message, you can reach both active and out-of-app users with engaging, relevant content.
Best Practices
Because of the volume of messages sent in an active app, it can be difficult to effectively sync real time activity, in-app alerts, and mobile push notifications. Developers often need to make considerations not to issue push alerts while users are active in the app to avoid damaging the user experience with unnecessary notifications.
You also need to consider which activity to send as push payloads. For example, if every message in a group chat channel triggers an automated message, users may quickly opt out of mobile push notifications entirely. In a related sense, you should decide how and whether to automatically limit app notifications based on user properties like user time zones.
Overall, manually managing real time, in-app activity, and mobile push notifications separately can become a burden for your developers. Developing, managing, and supporting multiple services (and streams of information) can quickly become a burden on time and resources better spent elsewhere.
Troubleshooting
You can debug push notification issues by inspecting the messages published to a {channelName}-pndebug
channel. For example, if you publish a message on channel ch1
, the corresponding debug channel is ch1-pndebug
.
You can subscribe to a debug channel using the PubNub Debug Console to troubleshoot push errors like invalid device tokens or invalid push payloads. For more information about push troubleshooting, refer to our Mobile Push Troubleshooting documentation.
If you are continuing to experience issues, please reach out to PubNub’s support team and include the results of the tests documented in the troubleshooting documentation.
What's Next?
Mobile push notifications are a great way to notify online and offline users about appointments, updates, previews of conversations, special offers, and so much more. Combine this with PubNub’s real time communication platform, and you have a complete application experience, giving you a way to continually engage and offer value to your users. PubNub’s Mobile Push Gateway makes it easy to send push notifications to your users, by acting as a bridge between the service providers and your application, meaning you don’t have to use different frameworks and SDKs to send different types of push notifications: you can do it all in one place, and let PubNub take care of the rest.
If you’re ready to start sending relevant, real time, and precise push notifications to your users, check out our documentation and tutorials on push notifications. If you would like more personal assistance, please reach out to us. We’ll walk you through the best way to add push notifications using our platform, and will work with you to get up and running with alerts that will inform, energize, and engage your users.