Mobile Push Notifications
Notify online and offline users about appointments, updates, conversations, and more.
Setup required
- Enable MOBILE PUSH NOTIFICATIONS in Admin Portal and configure APPLE PUSH CREDENTIALS or FIREBASE CLOUD MESSAGING.
- 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.
-
Server-to-server setup: In Admin Portal, enable MOBILE PUSH NOTIFICATIONS and configure APPLE PUSH CREDENTIALS (APNs Authentication Token
.p8file) or FIREBASE CLOUD MESSAGING (Firebase Server Key). -
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.
-
iOS only: Create a bundle ID for your app.
-
Register channels: Associate the device token with PubNub channels. Messages on those channels trigger push notifications. Update registrations anytime during the app lifecycle.
-
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 CreateInstance(). Separate options control sending and receiving.
1
Easy methods for (un)registering channels
Simplified methods wrap C# 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 linesRegister selected push channels
Register channels to receive push notifications for new messages:
RegisterForPush()- register a single channel (called onChannel)RegisterPushChannels()- register multiple channels (called onChat)
Method signature
These methods take the following parameters:
-
RegisterForPush()- lets you register a device on a single channel1channel.RegisterForPush(): Task<ChatOperationResult> -
RegisterPushChannels()- lets you register a device on multiple channels at once1chat.RegisterPushChannels(List<string> channelIds): Task<ChatOperationResult>
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:
| Parameter | Description |
|---|---|
channelIds *Type: List<string>Default: n/a | List of channels where you want your device to receive push notifications for sent messages. |
Output
| Type | Description |
|---|---|
Task<ChatOperationResult> | A ChatOperationResult indicating the success or failure of the operation. |
Sample code
1
List all push channels
Get all channels registered for push notifications on the device.
Method signature
This method has the following signature:
1chat.GetPushChannels(): Task<ChatOperationResult<List<string>>>
Input
This method doesn't take any parameters.
Output
| Type | Description |
|---|---|
Task<ChatOperationResult<List<string>>> | A ChatOperationResult containing a list of all channels registered to receive push notifications on a given device. |
Sample code
1
Unregister selected push channels
Stop receiving push notifications for specific channels:
UnRegisterFromPush()- unregister a single channel (called onChannel)UnRegisterPushChannels()- unregister multiple channels (called onChat)
Method signature
These methods take the following parameters:
-
UnRegisterFromPush()- lets you unregister a device from a single channel1channel.UnRegisterFromPush(): Task<ChatOperationResult> -
UnRegisterPushChannels()- lets you unregister a device from multiple channels at once1chat.UnRegisterPushChannels(List<string> channelIds): Task<ChatOperationResult>
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:
| Parameter | Description |
|---|---|
channelIds *Type: List<string>Default: n/a | List of channels where you want your device to unregister from receiving push notifications for sent messages. |
Output
| Type | Description |
|---|---|
Task<ChatOperationResult> | A ChatOperationResult indicating the success or failure of the operation. |
Sample code
1
Unregister all push channels
Disable push notifications for a device on all registered channels using UnRegisterAllPushChannels().
Method signature
This method has the following signature:
1chat.UnRegisterAllPushChannels(): Task<ChatOperationResult>
Input
This method doesn't take any parameters.
Output
| Type | Description |
|---|---|
Task<ChatOperationResult> | A ChatOperationResult indicating the success or failure of the operation. |
Sample code
1
Send custom push data
You can include custom data in push notification payloads when sending messages. Use the CustomPushData property of SendTextParams to pass additional key-value pairs that will be included in the push notification.
Sample code
1