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
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)
1pn.AddPushNotificationsOnChannels().
2 Channels([]string).
3 DeviceIDForPush(string).
4 PushType(PNPushTypeGCM|PNPushTypeAPNS2).
5 Topic(string).
6 Environment(PNPushEnvironment).
7 QueryParam(map[string]string).
8 Execute()
Parameter | Description |
---|---|
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
Add device to channel
1package main
2
3import (
4 "fmt"
5 "log"
6
7 pubnub "github.com/pubnub/go/v7"
8)
9
10func main() {
11 // Configure the PubNub instance with demo keys
12 config := pubnub.NewConfigWithUserId("myUniqueUserId")
13 config.SubscribeKey = "demo"
14 config.PublishKey = "demo"
15
show all 52 linesReturns
No payload is returned. Check status.Error
on the status object.
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)
1pn.ListPushProvisions().
2 DeviceIDForPush(string).
3 PushType(PNPushTypeGCM| PNPushTypeAPNS2).
4 Topic(string).
5 Environment(PNPushEnvironment).
6 QueryParam(map[string]string).
7 Execute()
Parameter | Description |
---|---|
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
1// GCM/FCM
2pn.ListPushProvisions().
3 DeviceIDForPush("device_id").
4 PushType(pubnub.PNPushTypeGCM).
5 Execute()
6
7// APNS2
8pn.ListPushProvisions().
9 DeviceIDForPush("device_id").
10 PushType(pubnub.PNPushTypeAPNS2).
11 Topic("com.example.bundle_id").
12 Environment(pubnub.PNPushEnvironmentProduction).
13 Execute()
Returns
Returns ListPushProvisionsRequestResponse
with:
Method | Description |
---|---|
Channels Type: []string | Channels associated with push notifications. |
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)
1pn.RemovePushNotificationsFromChannels().
2 Channels([]string).
3 DeviceIDForPush(string).
4 PushType(PNPushTypeGCM|PNPushTypeAPNS2).
5 Topic(string).
6 Environment(PNPushEnvironment).
7 QueryParam(map[string]string).
8 Execute()
Parameter | Description |
---|---|
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
1// FCM/GCM
2pn.RemovePushNotificationsFromChannels().
3 Channels([]string{"ch"}).
4 DeviceIDForPush("device_id").
5 PushType(pubnub.PNPushTypeGCM).
6 Execute()
7
8// APNS2
9pn.RemovePushNotificationsFromChannels().
10 Channels([]string{"ch"}).
11 DeviceIDForPush("device_id").
12 PushType(pubnub.PNPushTypeAPNS2).
13 Topic("com.example.bundle_id").
14 Environment(pubnub.PNPushEnvironmentProduction).
15 Execute()
Returns
No payload is returned. Check status.Error
on the status object.
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)
1pn.RemoveAllPushNotifications().
2 DeviceIDForPush(string).
3 PushType(PNPushTypeGCM| PNPushTypeAPNS2).
4 Topic(string).
5 Environment(PNPushEnvironment).
6 QueryParam(map[string]string).
7 Execute()
Parameter | Description |
---|---|
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
1// FCM/GCM
2pn.RemoveAllPushNotifications().
3 DeviceIDForPush("device_id").
4 PushType(pubnub.PNPushTypeGCM).
5 Execute()
6
7// APNS2
8pn.RemoveAllPushNotifications().
9 DeviceIDForPush("device_id").
10 PushType(pubnub.PNPushTypeAPNS2).
11 Topic("com.example.bundle_id").
12 Environment(pubnub.PNPushEnvironmentProduction).
13 Execute()
Returns
No payload is returned. Check status.Error
on the status object.