Mobile Push Notifications API for Vue 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).

To learn more, read about Mobile Push Notifications.

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)

Use the following method(s) in the Vue SDK:

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 token.
pushGateway *
Type: String
Default:
n/a
Accepted values: apns, apns2, gcm.
environment
Type: String
Default:
development
APNs environment. Required if pushGateway is apns2.
topic
Type: String
Default:
n/a
APNs topic (bundle identifier). Required if pushGateway is apns2.
callback
Type: Function
Default:
n/a
Callback on success or error.

Sample code

Add device to channel

1import PubNubVue from 'pubnub-vue';
2
3const pubnub = PubNubVue.getInstance();
4
5pubnub.push.addChannels(
6 {
7 channels: ['a', 'b'],
8 device: 'niceDevice',
9 pushGateway: 'apns' // apns, gcm,
10 },
11 function(status) {
12 if (status.error) {
13 console.log("operation failed w/ error:", status);
14 } else {
15 console.log("operation done!");
show all 18 lines

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.

List channels that have push notifications enabled for the specified device token.

Method(s)

Use the following method(s) in the Vue SDK:

1pubnub.push.listChannels({String device, String pushGateway, String environment, String topic},Function callback)
* required
ParameterDescription
device *
Type: String
Default:
n/a
Device token.
pushGateway *
Type: String
Default:
n/a
Accepted values: apns, apns2, gcm.
environment
Type: String
Default:
development
APNs environment. Required if pushGateway is apns2.
topic
Type: String
Default:
n/a
APNs topic (bundle identifier). Required if pushGateway is apns2.
callback
Type: Function
Default:
n/a
Callback on success or error.

Sample code

List channels for device

1import PubNubVue from 'pubnub-vue';
2
3const pubnub = PubNubVue.getInstance();
4
5pubnub.push.listChannels(
6 {
7 device: 'niceDevice',
8 pushGateway: 'apns' // apns, gcm
9 },
10 function(status, response) {
11 if (status.error) {
12 console.log("operation failed w/ error:", status);
13 return;
14 }
15
show all 21 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 mobile push notifications on a set of channels.

Method(s)

Use the following method(s) in the Vue SDK:

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 token.
pushGateway *
Type: String
Default:
n/a
Accepted values: apns, apns2, gcm.
environment
Type: String
Default:
development
APNs environment. Required if pushGateway is apns2.
topic
Type: String
Default:
n/a
APNs topic (bundle identifier). Required if pushGateway is apns2.
callback
Type: Function
Default:
n/a
Callback on success or error.

Sample code

Remove device from channel

1import PubNubVue from 'pubnub-vue';
2
3const pubnub = PubNubVue.getInstance();
4
5pubnub.push.removeChannels(
6 {
7 channels: ['a', 'b'],
8 device: 'niceDevice',
9 pushGateway: 'apns' // apns, gcm
10 },
11 function(status) {
12 if (status.error) {
13 console.log("operation failed w/ error:", status);
14 } else {
15 console.log("operation done!");
show all 18 lines

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 mobile push notifications from all channels registered with the specified device token.

Method(s)

Use the following method(s) in the Vue SDK:

1pubnub.push.deleteDevice({String device, String pushGateway, String environment, String topic},Function callback)
* required
ParameterDescription
device *
Type: String
Default:
n/a
Device token.
pushGateway *
Type: String
Default:
n/a
Accepted values: apns, apns2, gcm.
environment
Type: String
Default:
development
APNs environment. Required if pushGateway is apns2.
topic
Type: String
Default:
n/a
APNs topic (bundle identifier). Required if pushGateway is apns2.
callback
Type: Function
Default:
n/a
Callback on success or error.

Sample code

Remove all mobile push notifications

1import PubNubVue from 'pubnub-vue';
2
3const pubnub = PubNubVue.getInstance();
4
5pubnub.push.deleteDevice(
6 {
7 device: 'niceDevice',
8 pushGateway: 'apns' // apns, gcm
9 },
10 function(status) {
11 if (status.error) {
12 console.log("operation failed w/ error:", status);
13 } else {
14 console.log("operation done!");
15 }
show all 17 lines

Response

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