Mobile Push Notifications API for PubNub Dart SDK

Mobile Push Notifications feature enables developers to bridge native PubNub publishing with 3rd-party push notification services including Google Android FCM (Firebase Cloud Messaging) and Apple iOS APNs (Apple Push Notification service).

By using the Mobile Push Notifications feature, developers can eliminate the need for developing, configuring, and maintaining additional server-side components for third-party push notification providers.

To learn more, read about Mobile Push Notifications.

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. Read the support page 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:

pubnub.addPushChannels(
String deviceId,
PushGateway gateway,
Set<String> channels,
{String? topic,
Environment? environment,
Keyset? keyset,
String? using}
)
ParameterTypeRequiredDescription
deviceIdStringYesID of the device to add mobile push notifications on.
gatewayPushGatewayYesEnums for the back-end to use for push. Available values: apns2 for APNs, gcm for FCM, and mpns for MPNS.
channelsSet<String>YesChannels to add mobile push notifications for.
topicStringOptionalNotifications topic name (usually it is bundle identifier of application for Apple platform). Required only if gateway set to apns2.
environmentEnvironmentOptionalEnvironment within which device should manage list of channels with enabled notifications (works only if gateway set to apns2).
keysetKeysetOptionalOverride for the PubNub default keyset configuration.
usingStringOptionalKeyset name from the keysetStore to be used for this method call.

Basic Usage

Add Device to Channel

// for non apns2
var result =
await pubnub.addPushChannels('A332C23D', PushGateway.gcm, {'my_channel'});

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

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. Read the support page 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:

pubnub.listPushChannels(
String deviceId,
PushGateway gateway,
{String? topic,
Environment? environment,
Keyset? keyset,
String? using,
String? start,
int? count
}
)
ParameterTypeRequiredDescription
deviceIdStringYesID of the device to add mobile push notifications on.
gatewayPushGatewayYesThe back-end to use for push. Available values: apns2 for APNs, gcm for FCM, and mpns for MPNS.
topicStringOptionalNotifications topic name (usually it is bundle identifier of application for Apple platform). Required only if pushType set to apns2.
environmentEnvironmentOptionalEnvironment within which device should manage list of channels with enabled notifications (works only if gateway set to apns2).
keysetKeysetOptionalOverride for the PubNub default keyset configuration.
usingStringOptionalKeyset name from the keysetStore to be used for this method call.
startStringOptionalStarting channel for pagination. Use the last channel from the previous page request.
countintOptionalNumber of channels to return for pagination. Max of 1000 tokens at a time. Defaults to 500.

Basic Usage

List Channels For Device

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

// 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:

MethodTypeDescription
channelsListList 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. Read the support page 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:

pubnub.removePushChannels(
String deviceId,
PushGateway gateway,
Set<String> channels,
{String? topic,
Environment? environment,
Keyset? keyset,
String? using}
)
ParameterTypeRequiredDescription
deviceIdStringYesID of the device to remove mobile push notifications from.
gatewayPushGatewayYesEnums for the back-end to use for push. Available values: apns2 for APNs, gcm for FCM, and mpns for MPNS.
channelsSet<String>YesThe channels to remove.
topicStringOptionalNotifications topic name (usually it is bundle identifier of application for Apple platform). Required only if gateway set to apns2.
environmentEnvironmentOptionalEnvironment within which device should manage list of channels with enabled notifications (works only if gateway set to apns2).
keysetKeysetOptionalOverride for the PubNub default keyset configuration.
usingStringOptionalKeyset name from the keysetStore to be used for this method call.

Basic Usage

Remove Device From Channel

// for non apns2
var result2 = await pubnub
.removePushChannels('A332C23D', PushGateway.gcm, {'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. Read the support page 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:

pubnub.removeDevice(
String deviceId,
PushGateway gateway,
{String? topic,
Environment? environment,
Keyset? keyset,
String? using}
)
ParameterTypeRequiredDescription
deviceIdStringYesID of the device to remove mobile push notifications from.
gatewayPushGatewayYesEnums for the back-end to use for push. Available values: apns2 for APNs, gcm for FCM, and mpns for MPNS.
topicStringOptionalNotifications topic name (usually it is bundle identifier of application for Apple platform). Required only if gateway set to apns2.
environmentEnvironmentOptionalEnvironment within which device should manage list of channels with enabled notifications (works only if gateway set to apns2).
keysetKeysetOptionalOverride for the PubNub default keyset configuration.
usingStringOptionalKeyset name from the keysetStore to be used for this method call.

Basic Usage

Remove all mobile push notifications

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

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

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

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

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

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