---
source_url: https://www.pubnub.com/docs/sdks/dart/api-reference/mobile-push
title: Mobile Push Notifications API for Dart SDK
updated_at: 2026-06-12T11:25:11.193Z
sdk_name: PubNub Dart SDK
sdk_version: 7.1.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 Dart SDK

PubNub Dart SDK, use the latest version: 7.1.0

Install:

```bash
dart pub add pubnub@7.1.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).

## Add device to channel

:::note Requires Mobile Push Notifications add-on
This method requires that the Mobile Push Notifications add-on is enabled for your key in the [Admin Portal](https://admin.pubnub.com/). Read the [support page](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-) on enabling add-on features on your keys.
:::

Enable mobile push notifications on provided set of channels.

### Method(s)

To run `Adding Device to Channel` you can use the following method(s) in the Dart SDK:

```dart
pubnub.addPushChannels(
  String deviceId,
  PushGateway gateway,
  Set<String> channels,
  {String? topic,
  Environment? environment,
  Keyset? keyset,
  String? using}
) 
```

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| deviceId | String | Yes |  | ID of the device to add mobile push notifications on. |
| gateway | PushGateway | Yes |  | Enums for the back-end to use for push. Available values: `apns2` for APNs, `fcm` for FCM. |
| channels | Set<String> | Yes |  | Channels to add mobile push notifications for. |
| topic | String | Optional |  | Notifications topic name (usually it is bundle identifier of application for Apple platform). Required only if `gateway` set to `apns2`. |
| environment | Environment | Optional |  | Environment within which device should manage list of channels with enabled notifications (works only if `gateway` set to `apns2`). |
| keyset | Keyset | Optional |  | Override for the PubNub default keyset configuration. |
| using | String | Optional |  | Keyset name from the `keysetStore` to be used for this method call. |

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

```dart
import 'package:pubnub/pubnub.dart';

void main() async {
  // Create PubNub instance with default keyset.
  var pubnub = PubNub(
    defaultKeyset: Keyset(
      subscribeKey: 'demo',
      publishKey: 'demo',
      userId: UserId('myUniqueUserId'),
    ),
  );

  // Details for adding a device to push notifications
  String deviceId = 'A332C23D';
  Set<String> channels = {'my_channel'};
  
  // Adding device to channel using FCM
  try {
    await pubnub.addPushChannels(deviceId, PushGateway.fcm, channels);
    print('Device added to channels for FCM.');
  } catch (e) {
    print('Failed to add device to channels: $e');
  }
}
```

### Returns

The `addPushChannels()` does not return actionable data. In case of an error, an exception with error details is thrown.

## List channels for device

:::note Requires Mobile Push Notifications add-on
This method requires that the Mobile Push Notifications add-on is enabled for your key in the [Admin Portal](https://admin.pubnub.com/). Read the [support page](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-) on enabling add-on features on your keys.
:::

Request for all channels on which push notification has been enabled using specified pushToken.

### Method(s)

To run `Listing Channels For Device` you can use the following method(s) in the Dart SDK:

```dart
pubnub.listPushChannels(
  String deviceId,
  PushGateway gateway,
  {String? topic,
  Environment? environment,
  Keyset? keyset,
  String? using,
  String? start,
  int? count
  }
) 
```

| Parameter | Description |
| --- | --- |
| `deviceId` *Type: `String` | ID of the device to add mobile push notifications on. |
| `gateway` *Type: `PushGateway` | The back-end to use for push. Available values: `apns2` for APNs, `fcm` for FCM. |
| `topic`Type: `String` | Notifications topic name (usually it is bundle identifier of application for Apple platform). Required only if `pushType` set to `apns2`. |
| `environment`Type: `Environment` | Environment within which device should manage list of channels with enabled notifications (works only if `gateway` set to `apns2`). |
| `keyset`Type: `Keyset` | Override for the PubNub default keyset configuration. |
| `using`Type: `String` | Keyset name from the `keysetStore` to be used for this method call. |
| `start`Type: `String` | Starting channel for pagination. Use the last channel from the previous page request. |
| `count`Type: `int` | Number of channels to return for pagination. Max of 1000 tokens at a time. Defaults to 500. |

### Sample code

#### List channels for device

```dart
// for non apns2
var result = await pubnub.listPushChannels('A332C23D', PushGateway.fcm);

// for apns2
var result = await pubnub.listPushChannels('device-token', PushGateway.apns2,
  topic: 'MyAppTopic', environment: Environment.development);
```

### Returns

The `listPushChannels()` operation returns a `ListPushChannelsResult` which contains the following operations:

| Method | Description |
| --- | --- |
| `channels`Type: `List` | List of `channels` associated for mobile push notifications. |

## Remove device from channel

:::note Requires Mobile Push Notifications add-on
This method requires that the Mobile Push Notifications add-on is enabled for your key in the [Admin Portal](https://admin.pubnub.com/). Read the [support page](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-) on enabling add-on features on your keys.
:::

Disable mobile push notifications on provided set of channels.

### Method(s)

To Removing Device From Channel you can use the following method(s) in the Dart SDK:

```dart
pubnub.removePushChannels(
  String deviceId,
  PushGateway gateway,
  Set<String> channels,
  {String? topic,
  Environment? environment,
  Keyset? keyset,
  String? using}
) 
```

| Parameter | Description |
| --- | --- |
| `deviceId` *Type: `String` | ID of the device to remove mobile push notifications from. |
| `gateway` *Type: `PushGateway` | Enums for the back-end to use for push. Available values: `apns2` for APNs, `fcm` for FCM. |
| `channels` *Type: `Set<String>` | The channels to remove. |
| `topic`Type: `String` | Notifications topic name (usually it is bundle identifier of application for Apple platform). Required only if `gateway` set to `apns2`. |
| `environment`Type: `Environment` | Environment within which device should manage list of channels with enabled notifications (works only if `gateway` set to `apns2`). |
| `keyset`Type: `Keyset` | Override for the PubNub default keyset configuration. |
| `using`Type: `String` | Keyset name from the `keysetStore` to be used for this method call. |

### Sample code

#### Remove device from channel

```dart
// for non apns2
var result2 = await pubnub
  .removePushChannels('A332C23D', PushGateway.fcm, {'my_channel'});
    
// for apns2
var result = await pubnub.removePushChannels(
  'device-token', PushGateway.apns2, {'my_channel'},
  topic: 'MyAppTopic', environment: Environment.development);
```

### Returns

The `removePushChannels()` doesn't return actionable data. In case of an error, an exception with error details is thrown.

## Remove all mobile push notifications

:::note Requires Mobile Push Notifications add-on
This method requires that the Mobile Push Notifications add-on is enabled for your key in the [Admin Portal](https://admin.pubnub.com/). Read the [support page](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-) on enabling add-on features on your keys.
:::

Disable mobile push notifications from all channels registered with the specified pushToken.

### Method(s)

To `Remove all mobile push notifications` you can use the following method(s) in the Dart SDK:

```dart
pubnub.removeDevice(
  String deviceId,
  PushGateway gateway,
  {String? topic,
  Environment? environment,
  Keyset? keyset,
  String? using}
) 
```

| Parameter | Description |
| --- | --- |
| `deviceId` *Type: `String` | ID of the device to remove mobile push notifications from. |
| `gateway` *Type: `PushGateway` | Enums for the back-end to use for push. Available values: `apns2` for APNs, `fcm` for FCM. |
| `topic`Type: `String` | Notifications topic name (usually it is bundle identifier of application for Apple platform). Required only if `gateway` set to `apns2`. |
| `environment`Type: `Environment` | Environment within which device should manage list of channels with enabled notifications (works only if `gateway` set to `apns2`). |
| `keyset`Type: `Keyset` | Override for the PubNub default keyset configuration. |
| `using`Type: `String` | Keyset name from the `keysetStore` to be used for this method call. |

### Sample code

#### Remove all mobile push notifications

```dart
// for non apns2
var result = await pubnub.removeDevice('deviceId', PushGateway.fcm);

// for apns2
var result = await pubnub.removeDevice('device-token', PushGateway.apns2,
  topic: 'MyAppTopic', environment: Environment.development);
```

### Returns

The `removeDevice()` does not return actionable data. In case of an error, an exception with error details is thrown.

### Other examples

#### Short syntax

```dart
var device = pubnub.device('A332C23D');

// to register device for channels
var result = await device.registerToChannels({'my_channel'}, PushGateway.fcm);

// to remove device from channels
var result =
  await device.deregisterFromChannels({'my_channel'}, PushGateway.fcm);

// to remove all registrations for a device
var result = await device.remove(PushGateway.apns2,
  topic: 'MyAppTopic', environment: Environment.production);
```

## Terms in this document

* **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.