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
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}
)
Parameter | Type | Required | 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, gcm for FCM, and mpns for MPNS. |
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. |
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
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
}
)
Parameter | Type | Required | Description |
---|---|---|---|
deviceId | String | Yes | ID of the device to add mobile push notifications on. |
gateway | PushGateway | Yes | The back-end to use for push. Available values: apns2 for APNs, gcm for FCM, and mpns for MPNS. |
topic | String | Optional | Notifications topic name (usually it is bundle identifier of application for Apple platform). Required only if pushType 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. |
start | String | Optional | Starting channel for pagination. Use the last channel from the previous page request. |
count | int | Optional | Number 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:
Method | Type | Description |
---|---|---|
channels | List | List of channels associated for mobile push notifications. |
Remove Device From Channel
note
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}
)
Parameter | Type | Required | Description |
---|---|---|---|
deviceId | String | Yes | ID of the device to remove mobile push notifications from. |
gateway | PushGateway | Yes | Enums for the back-end to use for push. Available values: apns2 for APNs, gcm for FCM, and mpns for MPNS. |
channels | Set<String> | Yes | The channels to remove. |
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. |
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
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}
)
Parameter | Type | Required | Description |
---|---|---|---|
deviceId | String | Yes | ID of the device to remove mobile push notifications from. |
gateway | PushGateway | Yes | Enums for the back-end to use for push. Available values: apns2 for APNs, gcm for FCM, and mpns for MPNS. |
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. |
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);