Push Basics

Despite the advantages of in-app messaging, there are cases where you may want to deliver messages via Mobile Push Notifications. PubNub's Mobile Push Gateway provides a method to deliver messages fast and reliably regardless of whether the application is in the foreground or background on iOS and Android devices.

PubNub's Mobile Push Notifications feature bridges native PubNub publishing with third-party push notification services including Firebase Cloud Messaging (FCM) and Apple Push Notification Service (APNs). The push gateway is a great way to make sure that you can send important data and messages out to users even when they're not active in your mobile application.

Pricing

Push notification transactions are included in PubNub’s Monthly Active Users (MAU) pricing model. For more information, visit our Pricing page.

How it Works

When the Mobile Push Gateway is enabled, you may associate unique mobile devices tokens to PubNub channel names. Once this association is made, when a message is published to a channel, all associated devices will receive that message via their associated FCM or APNs service. Behind the scenes, the PubNub Mobile Push Gateway establishes an authenticated connection to the push providers based on your registered configuration.

Push notifications are delivered in the following manner:

  1. First, publish a message on a channel with the push payload.
  2. PubNub's Push Gateway checks device registrations and relays the message to push providers.
  3. FCM/APNs providers deliver the push notification to one or more devices.

Push Notification Delivery

Configuration

To use push notification on PubNub, you first need to enable the feature and set up FCM/APNs credentials for your application. Once you've obtained the credentials from your Apple or Firebase account, you can add those credentials or upload a certificate to the Admin Portal. See how to enable Push Notifications.

Push Register

Registering Devices

To be able to receive notifications, the app will need to register its Device Token (provided by the application's platform) with a PubNub channel or channels. This registration can be changed at any time during the applications lifecycle by adding additional channels or removing previously registered channels. This allows you to curate a variety of channel-specific messages, and dynamically change each channel's targeted device lists in real time.

Sending Notifications

To send a push notification, include the appropriate push notification payload for APNs, FCM, or both when you publish a message and PubNub will appropriately parse the message. When PubNub finds the pn_apns and pn_gcm payloads, it will retrieve all device tokens that are associated with pushing to the target channel and forward a push notification request to the appropriate push service for those associated devices.

Receiving Notifications

Once the PubNub Push Gateway sends the notification to APNs or FCM push providers, the notifications are delivered to the mobile device. Note that PubNub isn't involved in the actual delivery of the notification to each devicethat's handled by the push providers.

If the user is active on the app, they will receive the in-app message directly by subscribing to PubNub and push notifications may not be necessary. For this, developers should actually mute the push notification using the functionality provided by the app platform instead of muting the real-time message from PubNub.

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 payload.

For more information about push troubleshooting, refer to Mobile Push Troubleshooting.