Mobile Push Notifications API for AngularJs 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).
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.
Add a device to a push notifications channel
note
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)
Pubnub.push.addChannels({Array channels, String device, String pushGateway},Function callback)
Parameter | Description |
---|---|
channels *Type: Array | Channels to enable for push notifications. |
device *Type: String | Device ID (push token). |
pushGateway *Type: String | apns or gcm . |
callback Type: Function | Callback invoked on completion. |
Sample code
Pubnub.push.addChannels(
{
channels: ['my_chat'],
device: 'A655FBA9931AB',
pushGateway: 'apns' // apns, gcm
},
function(status) {
if (status.error) {
console.log("operation failed w/ error:", status);
} else {
console.log("operation done!")
}
}
);
Response
{
error: false,
operation: 'PNPushNotificationEnabledChannelsOperation',
statusCode: 200
}
List push notifications channels for a device
note
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)
Pubnub.push.listChannels({String device, String pushGateway},Function callback)
Parameter | Description |
---|---|
device *Type: String | Device ID (push token). |
pushGateway *Type: String | apns or gcm . |
callback Type: Function | Callback invoked on completion. |
Sample code
Pubnub.push.listChannels(
{
device: 'A655FBA9931AB',
pushGateway: 'apns' // apns, gcm
},
function (status, response) {
if (status.error) {
console.log("operation failed w/ error:", status);
return;
}
console.log("listing push channel for device")
response.channels.forEach( function (channel) {
console.log(channel)
})
show all 17 linesResponse
// Example of status
{
error: false,
operation: 'PNPushNotificationEnabledChannelsOperation',
statusCode: 200
}
// Example of response
{
channels: [ 'a', 'b' ]
}
Remove a device from push notifications channels
note
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)
Pubnub.push.removeChannels({Array channels, String device, String pushGateway},Function callback)
Parameter | Description |
---|---|
channels *Type: Array | Channels to disable for push notifications. |
device *Type: String | Device ID (push token). |
pushGateway *Type: String | apns or gcm . |
callback Type: Function | Callback invoked on completion. |
Sample code
Pubnub.push.removeChannels(
{
channels: ['my_chat'],
device: 'A655FBA9931AB',
pushGateway: 'apns' // apns, gcm
},
function(status) {
if (status.error) {
console.log("operation failed w/ error:", status);
} else {
console.log("operation done!")
}
}
);
Response
{
error: false,
operation: 'PNPushNotificationEnabledChannelsOperation',
statusCode: 200
}
Remove a device from all push notifications channels
note
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)
Pubnub.push.deleteDevice({String device, String pushGateway},Function callback)
Parameter | Description |
---|---|
device *Type: String | Device ID (push token). |
pushGateway *Type: String | apns or gcm . |
callback Type: Function | Callback invoked on completion. |
Sample code
Pubnub.push.deleteDevice(
{
device: 'A655FBA9931AB',
pushGateway: 'apns' // apns, gcm
},
function (status) {
if (status.error) {
console.log("operation failed w/ error:", status);
} else {
console.log("operation done!")
}
}
);
Response
{
error: false,
operation: 'PNPushNotificationEnabledChannelsOperation',
statusCode: 200
}