Mobile Push Notifications API for Angular2 SDK

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

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. See how to enable add-on features.

Enable mobile push notifications on a set of channels.

Method(s)

1pubnub.push.addChannels({Array channels, String device, String pushGateway, String environment, String topic},Function callback)
* required
ParameterDescription
channels *
Type: Array
Default:
n/a
Channels to enable for push notifications.
device *
Type: String
Default:
n/a
Device ID (push token).
pushGateway *
Type: String
Default:
n/a
apns, apns2 or gcm.
environment
Type: String
Default:
development
APNs environment (for apns2).
topic
Type: String
Default:
n/a
APNs topic (bundle identifier). Required for apns2.
callback
Type: Function
Default:
n/a
Callback invoked on completion.

Sample code

Add device to channel

1pubnub.push.addChannels(
2 {
3 channels: ['my_chat'],
4 device: 'A655FBA9931AB',
5 pushGateway: 'apns' // apns, gcm
6 },
7 function(status) {
8 if (status.error) {
9 console.log("operation failed w/ error:", status);
10 } else {
11 console.log("operation done!")
12 }
13 }
14);

Response

1{
2 error: false,
3 operation: 'PNPushNotificationEnabledChannelsOperation',
4 statusCode: 200
5}

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. See how to enable add-on features.

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

Method(s)

1pubnub.push.listChannels({String device, String pushGateway, String environment, String topic},Function callback)
* required
ParameterDescription
device *
Type: String
Default:
n/a
Device ID (push token).
pushGateway *
Type: String
Default:
n/a
apns, apns2 or gcm.
environment
Type: String
Default:
development
APNs environment (for apns2).
topic
Type: String
Default:
n/a
APNs topic (bundle identifier). Required for apns2.
callback
Type: Function
Default:
n/a
Callback invoked on completion.

Sample code

List channels for device

1pubnub.push.listChannels(
2 {
3 device: 'A655FBA9931AB',
4 pushGateway: 'apns' // apns, gcm
5 },
6 function (status, response) {
7 if (status.error) {
8 console.log("operation failed w/ error:", status);
9 return;
10 }
11
12 console.log("listing push channel for device");
13 response.channels.forEach( function (channel) {
14 console.log(channel);
15 });
show all 17 lines

Response

1// Example of status
2{
3 error: false,
4 operation: 'PNPushNotificationEnabledChannelsOperation',
5 statusCode: 200
6}
7
8// Example of response
9{
10 channels: [ 'a', 'b' ]
11}

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. See how to enable add-on features.

Disable push notifications on selected channels.

Method(s)

1pubnub.push.removeChannels({Array channels, String device, String pushGateway, String environment, String topic},Function callback)
* required
ParameterDescription
channels *
Type: Array
Default:
n/a
Channels to disable for push notifications.
device *
Type: String
Default:
n/a
Device ID (push token).
pushGateway *
Type: String
Default:
n/a
apns, apns2 or gcm.
environment
Type: String
Default:
development
APNs environment (for apns2).
topic
Type: String
Default:
n/a
APNs topic (bundle identifier). Required for apns2.
callback
Type: Function
Default:
n/a
Callback invoked on completion.

Sample code

Remove device from channel

1pubnub.push.removeChannels(
2 {
3 channels: ['my_chat'],
4 device: 'A655FBA9931AB',
5 pushGateway: 'apns' // apns, gcm
6 },
7 function(status) {
8 if (status.error) {
9 console.log("operation failed w/ error:", status);
10 } else {
11 console.log("operation done!");
12 }
13 }
14);

Response

1{
2 error: false,
3 operation: 'PNPushNotificationEnabledChannelsOperation',
4 statusCode: 200
5}

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. See how to enable add-on features.

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

Method(s)

1pubnub.push.deleteDevice({String device, String pushGateway, String environment, String topic},Function callback)
* required
ParameterDescription
device *
Type: String
Default:
n/a
Device ID (push token).
pushGateway *
Type: String
Default:
n/a
apns, apns2 or gcm.
environment
Type: String
Default:
development
APNs environment (for apns2).
topic
Type: String
Default:
n/a
APNs topic (bundle identifier). Required for apns2.
callback
Type: Function
Default:
n/a
Callback invoked on completion.

Sample code

Remove all mobile push notifications

1pubnub.push.deleteDevice(
2 {
3 device: 'A655FBA9931AB',
4 pushGateway: 'apns' // apns, gcm
5 },
6 function (status) {
7 if (status.error) {
8 console.log("operation failed w/ error:", status);
9 } else {
10 console.log("operation done!");
11 }
12 }
13);

Response

1{
2 error: false,
3 operation: 'PNPushNotificationEnabledChannelsOperation',
4 statusCode: 200
5}
Last updated on