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
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)
1pn.AddPushNotificationsOnChannels().
2 Channels([]string).
3 DeviceIDForPush(string).
4 PushType(PNPushTypeFCM|PNPushTypeAPNS2).
5 Topic(string).
6 Environment(PNPushEnvironment).
7 QueryParam(map[string]string).
8 Execute()
Channelsrequired#- Channels to enable for push notifications.
DeviceIDForPushrequired#- Device ID (push token).
PushTyperequired#- Accepted values:
PNPushTypeAPNS2,PNPushTypeFCM. Topic#- APNs topic (bundle identifier).
Environment#- APNs environment. Accepted values:
PNPushEnvironmentDevelopment,PNPushEnvironmentProduction. QueryParam#- Map of query parameters to append to the API request.
Sample code
Add device to channel (FCM)
1// Replace with your package name (usually "main")
2package pubnub_samples_test
3
4import (
5 "fmt"
6
7 pubnub "github.com/pubnub/go/v10"
8)
9
10// Example_addChannelsToPushFCM demonstrates registering a device for FCM push notifications
11func Example_addChannelsToPushFCM() {
12 config := pubnub.NewConfigWithUserId(pubnub.UserId("demo-user"))
13 config.SubscribeKey = "demo" // Replace with your subscribe key
14 config.PublishKey = "demo" // Replace with your publish key
15
show all 37 linesAdd device to channel (APNs2)
1// Replace with your package name (usually "main")
2package pubnub_samples_test
3
4import (
5 "fmt"
6
7 pubnub "github.com/pubnub/go/v10"
8)
9
10// Example_addChannelsToPushAPNS2 demonstrates registering a device for APNs2 push notifications
11func Example_addChannelsToPushAPNS2() {
12 config := pubnub.NewConfigWithUserId(pubnub.UserId("demo-user"))
13 config.SubscribeKey = "demo" // Replace with your subscribe key
14 config.PublishKey = "demo" // Replace with your publish key
15
show all 39 linesReturns
No payload is returned. Check status.Error on the status object.
List push notifications channels for a device
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)
1pn.ListPushProvisions().
2 DeviceIDForPush(string).
3 PushType(PNPushTypeFCM|PNPushTypeAPNS2).
4 Topic(string).
5 Environment(PNPushEnvironment).
6 QueryParam(map[string]string).
7 Execute()
DeviceIDForPushrequired#- Device ID (push token).
PushTyperequired#- Accepted values:
PNPushTypeAPNS2,PNPushTypeFCM. Topic#- APNs topic (bundle identifier).
Environment#- APNs environment. Accepted values:
PNPushEnvironmentDevelopment,PNPushEnvironmentProduction. QueryParam#- Map of query parameters to append to the API request.
Sample code
List channels for device (FCM)
1// Replace with your package name (usually "main")
2package pubnub_samples_test
3
4import (
5 "fmt"
6
7 pubnub "github.com/pubnub/go/v10"
8)
9
10// Example_listPushChannelsFCM demonstrates listing channels with push enabled for an FCM device
11func Example_listPushChannelsFCM() {
12 config := pubnub.NewConfigWithUserId(pubnub.UserId("demo-user"))
13 config.SubscribeKey = "demo" // Replace with your subscribe key
14 config.PublishKey = "demo" // Replace with your publish key
15
show all 48 linesList channels for device (APNs2)
1// Replace with your package name (usually "main")
2package pubnub_samples_test
3
4import (
5 "fmt"
6
7 pubnub "github.com/pubnub/go/v10"
8)
9
10// Example_listPushChannelsAPNS2 demonstrates listing channels with push enabled for an APNs2 device
11func Example_listPushChannelsAPNS2() {
12 config := pubnub.NewConfigWithUserId(pubnub.UserId("demo-user"))
13 config.SubscribeKey = "demo" // Replace with your subscribe key
14 config.PublishKey = "demo" // Replace with your publish key
15
show all 40 linesReturns
Returns ListPushProvisionsRequestResponse with:
Channels#- Channels associated with push notifications.
Remove a device from push notifications channels
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)
1pn.RemovePushNotificationsFromChannels().
2 Channels([]string).
3 DeviceIDForPush(string).
4 PushType(PNPushTypeFCM|PNPushTypeAPNS2).
5 Topic(string).
6 Environment(PNPushEnvironment).
7 QueryParam(map[string]string).
8 Execute()
Channelsrequired#- Channels to disable for push notifications.
DeviceIDForPushrequired#- Device ID (push token).
PushTyperequired#- Accepted values:
PNPushTypeAPNS2,PNPushTypeFCM. Topic#- APNs topic (bundle identifier).
Environment#- APNs environment. Accepted values:
PNPushEnvironmentDevelopment,PNPushEnvironmentProduction. QueryParam#- Map of query parameters to append to the API request.
Sample code
Remove device from channel (FCM)
1// Replace with your package name (usually "main")
2package pubnub_samples_test
3
4import (
5 "fmt"
6
7 pubnub "github.com/pubnub/go/v10"
8)
9
10// Example_removeChannelsFromPushFCM demonstrates removing specific channels from FCM push notifications
11func Example_removeChannelsFromPushFCM() {
12 config := pubnub.NewConfigWithUserId(pubnub.UserId("demo-user"))
13 config.SubscribeKey = "demo" // Replace with your subscribe key
14 config.PublishKey = "demo" // Replace with your publish key
15
show all 37 linesRemove device from channel (APNs2)
1// Replace with your package name (usually "main")
2package pubnub_samples_test
3
4import (
5 "fmt"
6
7 pubnub "github.com/pubnub/go/v10"
8)
9
10// Example_removeChannelsFromPushAPNS2 demonstrates removing specific channels from APNs2 push notifications
11func Example_removeChannelsFromPushAPNS2() {
12 config := pubnub.NewConfigWithUserId(pubnub.UserId("demo-user"))
13 config.SubscribeKey = "demo" // Replace with your subscribe key
14 config.PublishKey = "demo" // Replace with your publish key
15
show all 39 linesReturns
No payload is returned. Check status.Error on the status object.
Remove a device from all push notifications channels
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)
1pn.RemoveAllPushNotifications().
2 DeviceIDForPush(string).
3 PushType(PNPushTypeFCM|PNPushTypeAPNS2).
4 Topic(string).
5 Environment(PNPushEnvironment).
6 QueryParam(map[string]string).
7 Execute()
DeviceIDForPushrequired#- Device ID (push token).
PushTyperequired#- Accepted values:
PNPushTypeAPNS2,PNPushTypeFCM. Topic#- APNs topic (bundle identifier).
Environment#- APNs environment. Accepted values:
PNPushEnvironmentDevelopment,PNPushEnvironmentProduction. QueryParam#- Map of query parameters to append to the API request.
Sample code
Remove all mobile push notifications (FCM)
1// Replace with your package name (usually "main")
2package pubnub_samples_test
3
4import (
5 "fmt"
6
7 pubnub "github.com/pubnub/go/v10"
8)
9
10// Example_removeAllPushChannelsFCM demonstrates removing all channels from FCM push notifications
11func Example_removeAllPushChannelsFCM() {
12 config := pubnub.NewConfigWithUserId(pubnub.UserId("demo-user"))
13 config.SubscribeKey = "demo" // Replace with your subscribe key
14 config.PublishKey = "demo" // Replace with your publish key
15
show all 37 linesRemove all mobile push notifications (APNs2)
1// Replace with your package name (usually "main")
2package pubnub_samples_test
3
4import (
5 "fmt"
6
7 pubnub "github.com/pubnub/go/v10"
8)
9
10// Example_removeAllPushChannelsAPNS2 demonstrates removing all channels from APNs2 push notifications
11func Example_removeAllPushChannelsAPNS2() {
12 config := pubnub.NewConfigWithUserId(pubnub.UserId("demo-user"))
13 config.SubscribeKey = "demo" // Replace with your subscribe key
14 config.PublishKey = "demo" // Replace with your publish key
15
show all 39 linesReturns
No payload is returned. Check status.Error on the status object.