---
source_url: https://www.pubnub.com/docs/sdks/c-sharp/api-reference/mobile-push
title: Mobile Push Notifications API for C# SDK
updated_at: 2026-06-09T11:07:42.419Z
sdk_name: PubNub C# SDK
sdk_version: 8.3.0
---

> 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 API for C# SDK

PubNub C# SDK, use the latest version: 8.3.0

Install:

```bash
dotnet add package PubNub@8.3.0
```

The Mobile Push Notifications feature connects native PubNub publishing to third-party push services. Supported services include Google Android FCM (Firebase Cloud Messaging) and Apple iOS APNs (Apple Push Notification service).

To learn more, read about [Mobile Push Notifications](https://www.pubnub.com/docs/general/push/send).

:::tip Request execution
Use `try`/`catch` when working with the C# SDK.
If a request has invalid parameters (for example, a missing required field), the SDK throws an exception. If the request reaches the server but fails (server error or network issue), the error details are available in the returned `status`.
```csharp
try
{
    PNResult<PNPublishResult> publishResponse = await pubnub.Publish()
        .Message("Why do Java developers wear glasses? Because they can't C#.")
        .Channel("my_channel")
        .ExecuteAsync();
    PNStatus status = publishResponse.Status;
    Console.WriteLine("Server status code : " + status.StatusCode.ToString());
}
catch (Exception ex)
{
    Console.WriteLine($"Request can't be executed due to error: {ex.Message}");
}
```
:::

## Add a device to a push notifications channel

:::note Requires Mobile Push Notifications add-on
Enable Mobile Push Notifications for your key in the [Admin Portal](https://admin.pubnub.com/). See how to [enable add-on features](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-).
:::

Enable mobile push notifications on a set of channels.

### Method(s)

```csharp
pubnub.AddPushNotificationsOnChannels()
        .PushType(PNPushType)
        .Channels(Array)
        .DeviceId(string)
        .Environment(PushEnvironment)
        .Topic(string)
        .QueryParam(Dictionary<string,object>)
```

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| PushType | PNPushType | Yes |  | Push type. One of: `PNPushType.FCM` or `PNPushType.APNS2` |
| Channels | Array | Yes |  | Channels to enable for push notifications. |
| DeviceId | string | Yes |  | Device ID (push token). |
| Environment | PushEnvironment | Optional |  | APNs environment (`Development`, `Production`). |
| Topic | string | Optional |  | APNs topic (bundle identifier). |
| QueryParam | Dictionary<string, | Optional |  | Name/value pairs to send as query parameters. |
| Async | PNCallback | Optional |  | Deprecated; prefer ExecuteAsync. |
| Execute | PNCallback | Yes |  | Callback of type `PNPushAddChannelResult`. |
| ExecuteAsync | None | Optional |  | Returns `PNResult<PNPushAddChannelResult>`. |

### Sample code

:::tip Reference code
This example is a self-contained code snippet ready to be run. It includes necessary imports and executes methods with console logging. Use it as a reference when working with other examples in this document.
:::

#### Add device to channel

```csharp
using PubnubApi;

public class PushNotificationCallback : PNCallback<PNPushAddChannelResult>
{
    public override void OnResponse(PNPushAddChannelResult result, PNStatus status)
    {
        if (!status.Error && result != null)
        {
            Console.WriteLine("Push notifications added to channels successfully.");
        }
        else
        {
            Console.WriteLine("Failed to add push notifications: " + pubnub.JsonPluggableLibrary.SerializeToJsonString(status));
        }
    }
}
    
public static void AddDeviceToChannelBasicUsage()
{
    // Configuration
    PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
    {
        SubscribeKey = "demo",
        PublishKey = "demo",
        Secure = true
    };

    // Initialize PubNub
    Pubnub pubnub = new Pubnub(pnConfiguration);
        
    try
    {
        // For FCM
        pubnub.AddPushNotificationsOnChannels()
            .PushType(PNPushType.FCM)
            .Channels(new string[] { "ch1", "ch2", "ch3" })
            .DeviceId("googleDevice")
            .Execute(new PushNotificationCallback());
    }
    catch (Exception ex)
    {
        Console.WriteLine($"FCM operation failed due to error: {ex.Message}");
    }

    try
    {
        // For APNS2
        pubnub.AddPushNotificationsOnChannels()
            .PushType(PNPushType.APNS2)
            .Channels(new string[] { "ch1", "ch2", "ch3" })
            .DeviceId("appleDevice")
            .Topic("myapptopic")
            .Environment(PushEnvironment.Development)
            .Execute(new PushNotificationCallback());
    }
    catch (Exception ex)
    {
        Console.WriteLine($"APNS2 operation failed due to error: {ex.Message}");
    }
}
```

### Returns

No payload is returned. Check `status.isError()` on the status object.

## List push notifications channels for a device

:::note Requires Mobile Push Notifications add-on
Enable Mobile Push Notifications for your key in the [Admin Portal](https://admin.pubnub.com/). See how to [enable add-on features](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-).
:::

Get all channels with push notifications for the specified push token.

### Method(s)

```csharp
pubnub.AuditPushChannelProvisions()
        .DeviceId(string)
        .PushType(PNPushType)
        .Environment(PushEnvironment)
        .Topic(string)
        .QueryParam(Dictionary<string,object>)
```

| Parameter | Description |
| --- | --- |
| `DeviceId` *Type: string | Device ID (push token). |
| `PushType` *Type: PNPushType | Push type. One of: `PNPushType.FCM` or `PNPushType.APNS2` |
| `Environment`Type: `PushEnvironment` | APNs environment (`Development`, `Production`). |
| `Topic`Type: string | APNs topic (bundle identifier). |
| `QueryParam`Type: Dictionary`<string, object>` | Name/value pairs to send as query parameters. |
| AsyncType: PNCallback | Deprecated; prefer ExecuteAsync. |
| `Execute` *Type: PNCallback | Callback of type `PNPushListProvisionsResult`. |
| `ExecuteAsync`Type: None | Returns `PNResult<PNPushListProvisionsResult>`. |

### Sample code

#### List channels for device

```csharp
using PubnubApi;

// Configuration
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo",
    Secure = true
};

// Initialize PubNub
Pubnub pubnub = new Pubnub(pnConfiguration);
        
// for FCM/GCM
pubnub.AuditPushChannelProvisions()
    .DeviceId("googleDevice")
    .PushType(PNPushType.FCM)
    .Execute(new PNPushListProvisionsResultExt((r, s) =>
    {
        Console.WriteLine(pubnub.JsonPluggableLibrary.SerializeToJsonString(r));
    }));

// for APNS2
pubnub.AuditPushChannelProvisions()
    .DeviceId("appleDevice")
    .PushType(PNPushType.APNS2)
    .Topic("myapptopic")
    .Environment(PushEnvironment.Development)
    .Execute(new PNPushListProvisionsResultExt((r, s) =>
    {
        Console.WriteLine(pubnub.JsonPluggableLibrary.SerializeToJsonString(r));
    }));
```

### Returns

Returns `PNPushListProvisionsResult` with:

| Property Name | Type | Description |
| --- | --- | --- |
| `Channels` | List`<string>` | Channels associated with push notifications. |

## Remove a device from push notifications channels

:::note Requires Mobile Push Notifications add-on
Enable Mobile Push Notifications for your key in the [Admin Portal](https://admin.pubnub.com/). See how to [enable add-on features](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-).
:::

Disable push notifications on selected channels.

### Method(s)

```csharp
pubnub.RemovePushNotificationsFromChannels()
        .DeviceId(string)
        .Channels(Array)
        .PushType(PNPushType)
        .Environment(PushEnvironment)
        .Topic(string)
        .QueryParam(Dictionary<string,object>)
```

| Parameter | Description |
| --- | --- |
| `DeviceId` *Type: string | Device ID (push token). |
| `Channels` *Type: Array | Channels to disable for push notifications. |
| `PushType` *Type: PNPushType | Push type. One of: `PNPushType.FCM` or `PNPushType.APNS2` |
| `Environment`Type: `PushEnvironment` | APNs environment (`Development`, `Production`). |
| `Topic`Type: string | APNs topic (bundle identifier). |
| `QueryParam`Type: Dictionary`<string, object>` | Name/value pairs to send as query parameters. |
| AsyncType: PNCallback | Deprecated; prefer ExecuteAsync. |
| `Execute` *Type: PNCallback | Callback of type `PNPushRemoveChannelResult`. |
| `ExecuteAsync`Type: None | Returns `PNResult<PNPushRemoveChannelResult>`. |

### Sample code

#### Remove device from channel

```csharp
using PubnubApi;

// Configuration
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo",
    Secure = true
};

// Initialize PubNub
Pubnub pubnub = new Pubnub(pnConfiguration);
        
// for FCM/GCM
pubnub.RemovePushNotificationsFromChannels()
    .DeviceId("googleDevice")
    .Channels(new string[] {
        "ch1",
        "ch2",
        "ch3"
    })
    .PushType(PNPushType.FCM)
    .Execute(new PNPushRemoveChannelResultExt((r, s) =>
    {
        Console.WriteLine(pubnub.JsonPluggableLibrary.SerializeToJsonString(r));
    }));

// for APNS2
pubnub.RemovePushNotificationsFromChannels()
    .DeviceId("appleDevice")
    .Channels(new string[] {
        "ch1",
        "ch2",
        "ch3"
    })
    .PushType(PNPushType.APNS2)
    .Topic("myapptopic")
    .Environment(PushEnvironment.Development)
    .Execute(new PNPushRemoveChannelResultExt((r, s) =>
    {
        Console.WriteLine(pubnub.JsonPluggableLibrary.SerializeToJsonString(r));
    }));
```

### Returns

No payload is returned. Check `status.isError()` on the status object.

## Remove a device from all push notifications channels

:::note Requires Mobile Push Notifications add-on
Enable Mobile Push Notifications for your key in the [Admin Portal](https://admin.pubnub.com/). See how to [enable add-on features](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-).
:::

Disable push notifications from all channels registered for the specified push token.

### Method(s)

```csharp
pubnub.RemoveAllPushNotificationsFromDeviceWithPushToken()
        .DeviceId(string)
        .PushType(PNPushType)
        .Environment(PushEnvironment)
        .Topic(string)
        .QueryParam(Dictionary<string,object>)
```

| Parameter | Description |
| --- | --- |
| `DeviceId` *Type: string | Device ID (push token). |
| `PushType` *Type: PNPushType | Push type. One of: `PNPushType.FCM` or `PNPushType.APNS2` |
| `Environment`Type: `PushEnvironment` | APNs environment (`Development`, `Production`). |
| `Topic`Type: string | APNs topic (bundle identifier). |
| `QueryParam`Type: Dictionary`<string, object>` | Name/value pairs to send as query parameters. |
| AsyncType: PNCallback | Deprecated; prefer ExecuteAsync. |
| `Execute` *Type: PNCallback | Callback of type `PNPushRemoveAllChannelsResult`. |
| `ExecuteAsync`Type: None | Returns `PNResult<PNPushRemoveAllChannelsResult>`. |

### Sample code

#### Remove all mobile push notifications

```csharp
using PubnubApi;

// Configuration
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo",
    Secure = true
};

// Initialize PubNub
Pubnub pubnub = new Pubnub(pnConfiguration);
        
// for FCM/GCM
pubnub.RemoveAllPushNotificationsFromDeviceWithPushToken()
    .DeviceId("googleDevice")
    .PushType(PNPushType.FCM)
    .Execute(new PNPushRemoveAllChannelsResultExt((r, s) => {
        Console.WriteLine(pubnub.JsonPluggableLibrary.SerializeToJsonString(r));
    }));

// for APNS2
pubnub.RemoveAllPushNotificationsFromDeviceWithPushToken()
    .DeviceId("appleDevice")
    .PushType(PNPushType.APNS2)
    .Topic("myapptopic")
    .Environment(PushEnvironment.Development)
    .Execute(new PNPushRemoveAllChannelsResultExt((r, s) => {
        Console.WriteLine(pubnub.JsonPluggableLibrary.SerializeToJsonString(r));
    }));
```

### Returns

Returns `PNPushRemoveAllChannelsResult` with:

| Property Name | Type | Description |
| --- | --- | --- |
| `PNPushRemoveAllChannelsResult` | Object | Empty object on success. |
| `PNStatus` | Object | Request status (error or success). |

## Terms in this document

* **Channel** - A pathway for sending and receiving messages between devices, created automatically when you first use it, that can handle any number of users and messages for different communication needs, like 1-1 text chats, group conversations, and other data streaming.
* **PubNub** - PubNub is a real-time messaging platform that provides APIs and SDKs for building scalable applications. It handles the complex infrastructure of real-time communication, including: Message delivery and persistence, Presence detection, Access control, Push notifications, File sharing, Serverless processing with Functions and Events & Actions, Analytics and monitoring with BizOps Workspace, AI-powered insights with Illuminate.
* **Push token** - A device identifier issued by a push provider (APNs or FCM) used to register a device for receiving mobile push notifications.