On this page

Mobile Push Notifications

Notify online and offline users about appointments, updates, conversations, and more.

Setup required
  1. Enable MOBILE PUSH NOTIFICATIONS in Admin Portal and configure APPLE PUSH CREDENTIALS or FIREBASE CLOUD MESSAGING.
  2. Configure Chat SDK to send/receive push notifications.

How to set up push notifications

Configure your app to receive notifications via APNs (iOS) or FCM (Android). See the full documentation for SDK-specific details.

  1. Server-to-server setup: In Admin Portal, enable MOBILE PUSH NOTIFICATIONS and configure APPLE PUSH CREDENTIALS (APNs Authentication Token .p8 file) or FIREBASE CLOUD MESSAGING (Firebase Server Key).

  2. Get device token: Register your app with APNs or FCM to get a unique device token for targeting push notifications. See Apple and Google docs.

  3. iOS only: Create a bundle ID for your app.

  4. Register channels: Associate the device token with PubNub channels. Messages on those channels trigger push notifications. Update registrations anytime during the app lifecycle.

  5. Attach payload: Include provider-specific payload structure with each notification message.

What's improved in Chat SDK

Chat SDK simplifies push notification setup:

Simple configuration process

Configure push notifications once during initialization via init(). Separate options control sending and receiving.

Easy methods for (un)registering channels

Simplified methods wrap JavaScript SDK methods, eliminating repeated configuration:

Automatic payload creation

With sendPushes enabled, Chat SDK automatically attaches the correct payload structure to every message.

See this example:

1{
2 "fcm": {
3 "notification": {
4 // message author - either the name or ID (if the name is missing)
5 "title": "John Doe",
6 // content of the message
7 "text": "Hello, this is a test notification!"
8 }
9 },
10 "apns": {
11 "configurations": [
12 {
13 "targets": [
14 {
15 // for example, "com.apple.iMovie"
show all 28 lines

Register selected push channels

Register channels to receive push notifications for new messages:

  • registerForPush() - register a single channel (called on Channel)
  • registerPushChannels() - register multiple channels (called on Chat)
icon

Under the hood

Method signature

These methods take the following parameters:

  • registerForPush() - lets you register a device on a single channel

    1channel.registerForPush(): Promise<void>
  • registerPushChannels() - lets you register a device on multiple channels at once

    1chat.registerPushChannels(channels: string[]): Promise<void>

Input

As the registerForPush() method is invoked on the Channel object, it doesn't need to take any parameters. The channel the method is invoked on is the one registered.

The registerPushChannels() method takes the following parameters:

* required
ParameterDescription
channels *
Type: string[]
Default:
n/a
List of channels where you want your device to receive push notifications for sent messages.

Output

TypeDescription
Promise<void>
Method returns no output data.

Sample code

  • registerForPush()

    Receive push notifications for messages sent on the support channel.

    1// reference the "channel" object
    2const channel = await chat.getChannel("support")
    3// register this channel for push notifications
    4const registeredChannel = channel.registerForPush()
  • registerPushChannels()

    Receive push notifications for messages sent on the support and inicident-management channels.

    1const registeredChannel = await chat.registerPushChannels([
    2 "support",
    3 "inicident-management"
    4])

List all push channels

Get all channels registered for push notifications on the device.

icon

Under the hood

Method signature

This method has the following signature:

1chat.getPushChannels(): Promise<string[]>

Input

This method doesn't take any parameters.

Output

TypeDescription
Promise<string[]>
Returned list of all channels registered to receive push notifications on a given device.

Sample code

List all registered channels.

1const allRegisteredChannels = await chat.getPushChannels()

Unregister selected push channels

Stop receiving push notifications for specific channels:

  • unregisterFromPush() - unregister a single channel (called on Channel)
  • unregisterPushChannels() - unregister multiple channels (called on Chat)
icon

Under the hood

Method signature

These methods take the following parameters:

  • unregisterFromPush() - lets you unregister a device from a single channel

    1channel.unregisterFromPush(): Promise<void>
  • unregisterPushChannels() - lets you unregister a device from multiple channels at once

    1chat.unregisterPushChannels(channels: string[]): Promise<void>

Input

As the unregisterFromPush() method is invoked on the Channel object, it doesn't need to take any parameters. The channel the method is invoked on is the one unregistered.

The unregisterPushChannels() method takes the following parameters:

* required
ParameterDescription
channels *
Type: string[]
Default:
n/a
List of channels where you want your device to unregister from receiving push notifications for sent messages.

Output

TypeDescription
Promise<void>
Method returns no output data.

Sample code

  • unregisterFromPush()

    Stop receiving push notifications for messages sent on the support channel.

    1// reference the "channel" object
    2const channel = await chat.getChannel("support")
    3// unregister this channel from push notifications
    4channel.unregisterFromPush()
  • unregisterPushChannels()

    Stop receiving push notifications for messages sent on the support and inicident-management channels.

    1await chat.unregisterPushChannels([
    2 "support",
    3 "inicident-management"
    4])

Unregister all push channels

Disable push notifications for a device on all registered channels.

icon

Under the hood

Method signature

This method has the following signature:

1chat.unregisterAllPushChannels(): Promise<void>

Input

This method doesn't take any parameters.

Output

TypeDescription
Promise<void>
Method returns no output data.

Sample code

Disable push notifications on all registered channels.

1await chat.unregisterAllPushChannels()
Last updated on