Push Basics
Despite the advantages of in-app messaging, there are cases where you may want to deliver messages via Mobile Push Notifications. Mobile Push Notifications feature 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 Notifications feature 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 Nofitications feature establishes an authenticated connection to the push providers based on your registered configuration.
Push notifications are delivered in the following manner:
- First, publish a message on a channel with the push payload.
- PubNub's Push Gateway checks device registrations and relays the message to push providers.
- FCM/APNs providers deliver the push notification to one or more devices.
Configuration
To use Mobile Push Notifications on PubNub, you first need to enable and configure the feature on a chosen app's keyset in the Admin Portal.
Option | Description |
---|---|
Firebase Cloud Messaging | Connection details for FCM when you use it as a push service provider to deliver push notifications to your application. |
→ Private key file | Private key file downloaded from FCM. |
Apple Push Credentials | Connection details for APNs when you use it as a push service provider to deliver push notifications to your application. |
→ Team ID | 10-character string generated by Apple that’s assigned to your team. |
→ Auth Key ID | 10-character key identifier generated by Apple. |
→ Token file | Apple's authentication token signing key, like AuthKey_678PB6YGZ.p8 . |
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.
Register Devices
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.
Send 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_fcm
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.
Receive 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 device—that'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 mobile 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.