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

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 enable for push notifications.
DeviceIDForPush *
Type: string
Default:
n/a
Device ID (push token).
PushType *
Type: PNPushTypeGCM
PNPushTypeAPNS2
PNPushTypeFCM
Default:
Not set
Accepted values: PNPushTypeGCM, PNPushTypeAPNS2, PNPushTypeFCM.
Topic
Type: string
Default:
Not set
APNs topic (bundle identifier).
Environment
Type: PNPushEnvironment
Default:
PNPushEnvironmentDevelopment
APNs environment. Accepted values: PNPushEnvironmentDevelopment, PNPushEnvironmentProduction.
QueryParam
Type: map[string]string
Default:
n/a
Map of query parameters to append to the API request.

Sample code

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

No payload is returned. Check status.Error on the status object.

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)

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 (push token).
PushType *
Type: PNPushTypeGCM
PNPushTypeAPNS2
PNPushTypeFCM
Default:
Not set
Accepted values: PNPushTypeGCM, PNPushTypeAPNS2, PNPushTypeFCM.
Topic
Type: string
Default:
Not set
APNs topic (bundle identifier).
Environment
Type: PNPushEnvironment
Default:
PNPushEnvironmentDevelopment
APNs environment. Accepted values: PNPushEnvironmentDevelopment, PNPushEnvironmentProduction.
QueryParam
Type: map[string]string
Default:
n/a
Map of query parameters to append to the API request.

Sample code

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

Returns ListPushProvisionsRequestResponse with:

MethodDescription
Channels
Type: []string
Channels associated with push notifications.

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)

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 disable for push notifications.
DeviceIDForPush *
Type: string
Default:
n/a
Device ID (push token).
PushType *
Type: PNPushTypeGCM
PNPushTypeAPNS
PNPushTypeAPNS2
PNPushTypeFCM
Default:
Not set
Accepted values: PNPushTypeGCM, PNPushTypeAPNS2, PNPushTypeFCM.
Topic
Type: string
Default:
Not set
APNs topic (bundle identifier).
Environment
Type: PNPushEnvironment
Default:
PNPushEnvironmentDevelopment
APNs environment. Accepted values: PNPushEnvironmentDevelopment, PNPushEnvironmentProduction.
QueryParam
Type: map[string]string
Default:
n/a
Map of query parameters to append to the API request.

Sample code

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

No payload is returned. Check status.Error on the status object.

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)

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 (push token).
PushType *
Type: PNPushTypeGCM
PNPushTypeAPNS
PNPushTypeAPNS2
PNPushTypeFCM
Default:
Not set
Accepted values: PNPushTypeGCM, PNPushTypeAPNS2, PNPushTypeFCM.
Topic
Type: string
Default:
Not set
APNs topic (bundle identifier).
Environment
Type: PNPushEnvironment
Default:
PNPushEnvironmentDevelopment
APNs environment. Accepted values: PNPushEnvironmentDevelopment, PNPushEnvironmentProduction.
QueryParam
Type: map[string]string
Default:
n/a
Map of query parameters to append to the API request.

Sample code

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

No payload is returned. Check status.Error on the status object.

Last updated on