Mobile Push Notifications API for Go 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 a provided set of channels.

Method(s)

To run Adding Device to Channel you can use the following method(s) in the Go SDK:

pn.AddPushNotificationsOnChannels().
Channels([]string).
DeviceIDForPush(string).
PushType(PNPushTypeGCM|PNPushTypeAPNS2).
Topic(string).
Environment(PNPushEnvironment).
QueryParam(map[string]string).
Execute()
* required
ParameterDescription
Channels *
Type: []string
Default:
n/a
channels to add to the channel group
DeviceIDForPush *
Type: string
Default:
n/a
Device ID.
PushType *
Type: PNPushTypeGCM
PNPushTypeAPNS2
PNPushTypeFCM
Default:
Not set
Accepted values: PNPushTypeGCM, PNPushTypeAPNS2, PNPushTypeFCM.
Topic
Type: string
Default:
Not set
Notifications topic name (usually it is application's bundle identifier).
Environment
Type: PNPushEnvironment
Default:
PNPushEnvironmentDevelopment
Works only if PNPushType set to PNPushTypeAPNS2. Accepted values: PNPushEnvironmentDevelopment, PNPushEnvironmentProduction.
QueryParam
Type: map[string]string
Default:
n/a
QueryParam accepts a map, the keys and values of the map are passed as the query string parameters of the URL called by the API.

Basic Usage

Reference code

This example is a self-contained code snippet ready to be run. It includes necessary imports and executes methods with console logging. Use it as a reference when working with other examples in this document.

Add Device to Channel

package main

import (
"fmt"
"log"

pubnub "github.com/pubnub/go/v7"
)

func main() {
// Configure the PubNub instance with demo keys
config := pubnub.NewConfigWithUserId("myUniqueUserId")
config.SubscribeKey = "demo"
config.PublishKey = "demo"

show all 52 lines

Returns

The AddPushNotificationsOnChannels() does not return actionable data, be sure to check the status object on the outcome of the operation by checking the status.Error.

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 Go SDK:

pn.ListPushProvisions().
DeviceIDForPush(string).
PushType(PNPushTypeGCM| PNPushTypeAPNS2).
Topic(string).
Environment(PNPushEnvironment).
QueryParam(map[string]string).
Execute()
* required
ParameterDescription
DeviceIDForPush *
Type: string
Default:
n/a
Device ID.
PushType *
Type: PNPushTypeGCM
PNPushTypeAPNS2
PNPushTypeFCM
Default:
Not set
Accepted values: PNPushTypeGCM, PNPushTypeAPNS2, PNPushTypeFCM.
Topic
Type: string
Default:
Not set
Notifications topic name (usually it is application's bundle identifier).
Environment
Type: PNPushEnvironment
Default:
PNPushEnvironmentDevelopment
Works only if PNPushType set to PNPushTypeAPNS2. Accepted values: PNPushEnvironmentDevelopment, PNPushEnvironmentProduction.
QueryParam
Type: map[string]string
Default:
n/a
QueryParam accepts a map, the keys and values of the map are passed as the query string parameters of the URL called by the API.

Basic Usage

List Channels For Device

// GCM/FCM
pn.ListPushProvisions().
DeviceIDForPush("device_id").
PushType(pubnub.PNPushTypeGCM).
Execute()

// APNS2
pn.ListPushProvisions().
DeviceIDForPush("device_id").
PushType(pubnub.PNPushTypeAPNS2).
Topic("com.example.bundle_id").
Environment(pubnub.PNPushEnvironmentProduction).
Execute()

Returns

The ListPushProvisions() operation returns a ListPushProvisionsRequestResponse which contains the following operations:

MethodDescription
Channels
Type: []string
List 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 a provided set of channels.

Method(s)

To run Removing Device From Channel you can use the following method(s) in the Go SDK:

pn.RemovePushNotificationsFromChannels().
Channels([]string).
DeviceIDForPush(string).
PushType(PNPushTypeGCM|PNPushTypeAPNS2).
Topic(string).
Environment(PNPushEnvironment).
QueryParam(map[string]string).
Execute()
* required
ParameterDescription
Channels *
Type: []string
Default:
n/a
channels to add to the channel group
DeviceIDForPush *
Type: string
Default:
n/a
Device ID.
PushType *
Type: PNPushTypeGCM
PNPushTypeAPNS
PNPushTypeAPNS2
PNPushTypeFCM
Default:
Not set
Accepted values: PNPushTypeGCM, PNPushTypeAPNS2, PNPushTypeFCM.
Topic
Type: string
Default:
Not set
Notifications topic name (usually it is application's bundle identifier).
Environment
Type: PNPushEnvironment
Default:
PNPushEnvironmentDevelopment
Works only if PNPushType set to PNPushTypeAPNS2. Accepted values: PNPushEnvironmentDevelopment, PNPushEnvironmentProduction.
QueryParam
Type: map[string]string
Default:
n/a
QueryParam accepts a map, the keys and values of the map are passed as the query string parameters of the URL called by the API.

Basic Usage

Remove Device From Channel

// FCM/GCM
pn.RemovePushNotificationsFromChannels().
Channels([]string{"ch"}).
DeviceIDForPush("device_id").
PushType(pubnub.PNPushTypeGCM).
Execute()

// APNS2
pn.RemovePushNotificationsFromChannels().
Channels([]string{"ch"}).
DeviceIDForPush("device_id").
PushType(pubnub.PNPushTypeAPNS2).
Topic("com.example.bundle_id").
Environment(pubnub.PNPushEnvironmentProduction).
Execute()

Returns

The RemovePushNotificationsFromChannels() does not return actionable data, be sure to check the status object on the outcome of the operation by checking the status.Error.

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 run Remove all mobile push notifications, you can use the following method(s) in the Go SDK:

pn.RemoveAllPushNotifications().
DeviceIDForPush(string).
PushType(PNPushTypeGCM| PNPushTypeAPNS2).
Topic(string).
Environment(PNPushEnvironment).
QueryParam(map[string]string).
Execute()
* required
ParameterDescription
DeviceIDForPush *
Type: string
Default:
n/a
Device ID.
PushType *
Type: PNPushTypeGCM
PNPushTypeAPNS
PNPushTypeAPNS2
PNPushTypeFCM
Default:
Not set
Accepted values: PNPushTypeGCM, PNPushTypeAPNS2, PNPushTypeFCM.
Topic
Type: string
Default:
Not set
Notifications topic name (usually it is application's bundle identifier).
Environment
Type: PNPushEnvironment
Default:
PNPushEnvironmentDevelopment
Works only if PNPushType set to PNPushTypeAPNS2. Accepted values: PNPushEnvironmentDevelopment, PNPushEnvironmentProduction.
QueryParam
Type: map[string]string
Default:
n/a
QueryParam accepts a map, the keys and values of the map are passed as the query string parameters of the URL called by the API.

Basic Usage

Remove all mobile push notifications

// FCM/GCM
pn.RemoveAllPushNotifications().
DeviceIDForPush("device_id").
PushType(pubnub.PNPushTypeGCM).
Execute()

// APNS2
pn.RemoveAllPushNotifications().
DeviceIDForPush("device_id").
PushType(pubnub.PNPushTypeAPNS2).
Topic("com.example.bundle_id").
Environment(pubnub.PNPushEnvironmentProduction).
Execute()

Returns

The RemoveAllPushNotifications() does not return actionable data, be sure to check the status object on the outcome of the operation by checking the status.Error.

Last updated on