---
source_url: https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/push-notifications
title: Mobile Push Notifications
updated_at: 2026-06-05T11:10:04.465Z
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# Mobile Push Notifications

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

:::note Setup required
1. Enable **MOBILE PUSH NOTIFICATIONS** in [Admin Portal](https://admin.pubnub.com/) and configure **APPLE PUSH CREDENTIALS** or **FIREBASE CLOUD MESSAGING**.
2. [Configure Chat SDK](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/configuration#initialize-pubnub) to send/receive push notifications.
:::

## How to set up push notifications

Configure your app to receive notifications via [APNs](https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/sending_notification_requests_to_apns) (iOS) or [FCM](https://firebase.google.com/docs/cloud-messaging) (Android). See the [full documentation](https://www.pubnub.com/docs/general/push/send#configuration) 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](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/configuration#initialize-pubnub) via `CreateInstance()`. Separate options control sending and receiving.

```csharp
using System.Collections.Generic;
using System.Threading.Tasks;
using PubnubApi;
using PubnubChatApi;
using UnityEngine;

// Chat configuration with FCM push settings (APNS2 is also supported)
PubnubChatConfig chatConfig = new PubnubChatConfig()
{
    PushNotifications =
    {
        SendPushes = true, 
        DeviceGateway = PNPushType.FCM, 
        DeviceToken = "some_device"
    }
};
        
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo",
    Secure = true
};

// Initialize Unity Chat
var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration);
if (!chatResult.Error)
{
    chat = chatResult.Result;
}
```

### Easy methods for (un)registering channels

Simplified methods wrap [C# SDK methods](https://www.pubnub.com/docs/sdks/c-sharp/api-reference/mobile-push), eliminating repeated configuration:

* [Register channels](#register-selected-push-channels)
* [List registered channels](#list-all-push-channels)
* [Unregister selected](#unregister-selected-push-channels) or [all](#unregister-all-push-channels) channels

### Automatic payload creation

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

See this example:

```json
{
  "fcm": {
    "notification": {
      // message author - either the name or ID (if the name is missing)  
      "title": "John Doe",
      // content of the message
      "text": "Hello, this is a test notification!"
    }
  },
  "apns": {
    "configurations": [
      {
        "targets": [
          {
            // for example, "com.apple.iMovie"
            "topic": "com.domainname.applicationname"
          }
        ],
        "title": "John Doe",
        "text": "Hello, this is a test notification!",
        // default iOS sound for notifications
        "sound": "default",
        // name of the channel on which the message was published
        "subtitle": "Chat Room 1"
      }
    ]
  }
}
```

## 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`)

##### Under the hood

`RegisterForPush()` and `RegisterPushChannels()` call Mobile Push Notifications API and the C# SDK [AddPushNotificationsOnChannels()](https://www.pubnub.com/docs/sdks/c-sharp/api-reference/mobile-push#add-device-to-channel) method.

### Method signature

These methods take the following parameters:

* RegisterForPush() - lets you register a device on a single channel 1channel.RegisterForPush(): Task<ChatOperationResult>
* RegisterPushChannels() - lets you register a device on multiple channels at once 1chat.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 | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| channelIds | List<string> | Yes |  | 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

```csharp
using System.Collections.Generic;
using System.Threading.Tasks;
using PubnubApi;
using PubnubChatApi;
using UnityEngine;

// Chat configuration with FCM push settings (APNS2 is also supported)
PubnubChatConfig chatConfig = new PubnubChatConfig()
{
    PushNotifications =
    {
        SendPushes = true, 
        DeviceGateway = PNPushType.FCM, 
        DeviceToken = "some_device"
    }
};
        
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo",
    Secure = true
};

// Initialize Unity Chat
var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration);
if (!chatResult.Error)
{
    chat = chatResult.Result;
}
var getChannel = await chat.GetChannel("some_channel");
if (getChannel.Error)
{
    Debug.LogError($"Could not get channel! Error: {getChannel.Exception.Message}");
    return;
}
var channel = getChannel.Result;

var result = await channel.RegisterForPush();
if (result.Error)
{
    Debug.LogError($"Error when trying to register channel for push: {result.Exception.Message}");
}
        
//Alternatively you can also use:
await chat.RegisterPushChannels(new List<string>() { channel.Id });
```

## List all push channels

Get all channels registered for push notifications on the device.

##### Under the hood

`GetPushChannels()` calls Mobile Push Notifications API and the C# SDK [AuditPushChannelProvisions()](https://www.pubnub.com/docs/sdks/c-sharp/api-reference/mobile-push#list-channels-for-device) method.

### Method signature

This method has the following signature:

```csharp
chat.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

```csharp
using System.Collections.Generic;
using System.Threading.Tasks;
using PubnubApi;
using PubnubChatApi;
using UnityEngine;

// Chat configuration with FCM push settings (APNS2 is also supported)
PubnubChatConfig chatConfig = new PubnubChatConfig()
{
    PushNotifications =
    {
        SendPushes = true, 
        DeviceGateway = PNPushType.FCM, 
        DeviceToken = "some_device"
    }
};
        
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo",
    Secure = true
};

// Initialize Unity Chat
var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration);
if (!chatResult.Error)
{
    chat = chatResult.Result;
}
var getPushChannels = await chat.GetPushChannels();
if (getPushChannels.Error)
{
    Debug.LogError($"Error when trying to get all push channels: {getPushChannels.Exception.Message}");
}
foreach (var channelId in getPushChannels.Result)
{
    Debug.Log($"Found push channel with ID: {channelId}");
}
```

## 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`)

##### Under the hood

`UnRegisterFromPush()` and `UnRegisterPushChannels()` call Mobile Push Notifications API and the C# SDK [RemovePushNotificationsFromChannels()](https://www.pubnub.com/docs/sdks/c-sharp/api-reference/mobile-push#remove-device-from-channel) method.

### Method signature

These methods take the following parameters:

* UnRegisterFromPush() - lets you unregister a device from a single channel 1channel.UnRegisterFromPush(): Task<ChatOperationResult>
* UnRegisterPushChannels() - lets you unregister a device from multiple channels at once 1chat.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

```csharp
using System.Collections.Generic;
using System.Threading.Tasks;
using PubnubApi;
using PubnubChatApi;
using UnityEngine;

// Chat configuration with FCM push settings (APNS2 is also supported)
PubnubChatConfig chatConfig = new PubnubChatConfig()
{
    PushNotifications =
    {
        SendPushes = true, 
        DeviceGateway = PNPushType.FCM, 
        DeviceToken = "some_device"
    }
};
        
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo",
    Secure = true
};

// Initialize Unity Chat
var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration);
if (!chatResult.Error)
{
    chat = chatResult.Result;
}
var getChannel = await chat.GetChannel("some_channel");
if (getChannel.Error)
{
    Debug.LogError($"Could not get channel! Error: {getChannel.Exception.Message}");
    return;
}
var channel = getChannel.Result;

var result = await channel.UnRegisterFromPush();
if (result.Error)
{
    Debug.LogError($"Error when trying to unregister channel from push: {result.Exception.Message}");
}
        
//Alternatively you can also use:
await chat.UnRegisterPushChannels(new List<string>() { channel.Id });
```

## Unregister all push channels

Disable push notifications for a device on all registered channels using `UnRegisterAllPushChannels()`.

##### Under the hood

`UnRegisterAllPushChannels()` calls Mobile Push Notifications API and the C# SDK [RemoveAllPushNotificationsFromDeviceWithPushToken()](https://www.pubnub.com/docs/sdks/c-sharp/api-reference/mobile-push#remove-all-mobile-push-notifications) method.

### Method signature

This method has the following signature:

```csharp
chat.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

```csharp
using System.Collections.Generic;
using System.Threading.Tasks;
using PubnubApi;
using PubnubChatApi;
using UnityEngine;

// Chat configuration with FCM push settings (APNS2 is also supported)
PubnubChatConfig chatConfig = new PubnubChatConfig()
{
    PushNotifications =
    {
        SendPushes = true, 
        DeviceGateway = PNPushType.FCM, 
        DeviceToken = "some_device"
    }
};
        
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo",
    Secure = true
};

// Initialize Unity Chat
var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration);
if (!chatResult.Error)
{
    chat = chatResult.Result;
}
var result = await chat.UnRegisterAllPushChannels();
if (result.Error)
{
    Debug.LogError($"Error when trying to unregister all push channels: {result.Exception.Message}");
}
```

## 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

```csharp
using System.Collections.Generic;
using System.Threading.Tasks;
using PubnubApi;
using PubnubChatApi;
using UnityEngine;

// Chat configuration with FCM push settings (APNS2 is also supported)
PubnubChatConfig chatConfig = new PubnubChatConfig()
{
    PushNotifications =
    {
        SendPushes = true, 
        DeviceGateway = PNPushType.FCM, 
        DeviceToken = "some_device"
    }
};
        
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo",
    Secure = true
};

// Initialize Unity Chat
var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration);
if (!chatResult.Error)
{
    chat = chatResult.Result;
}
var getChannel = await chat.GetChannel("some_channel");
if (getChannel.Error)
{
    Debug.LogError($"Could not get channel! Error: {getChannel.Exception.Message}");
    return;
}
var channel = getChannel.Result;

await channel.SendText("some message",
    new SendTextParams()
        { CustomPushData = new Dictionary<string, string>() { { "some_key", "some_value" } } });
```