Push Notifications API for PubNub Go SDK

PubNub's Mobile Push Gateway 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 Gateway, 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 Push Notifications.

Adding Device to Channel

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.

Description

Enable 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 V4 SDK:

pn. AddPushNotificationsOnChannels().Channels([]string).DeviceIDForPush(string).PushType(PNPushTypeGCM|PNPushTypeAPNS2).Topic(string).Environment(PNPushEnvironment).QueryParam(map[string]string).Execute()
ParameterTypeRequiredDefaultDescription
Channels[]stringYeschannels to add to the channel group
DeviceIDForPushstringYesDevice ID.
PushTypePNPushTypeGCM
PNPushTypeAPNS2
PNPushTypeFCM
YesNot setAccepted values: PNPushTypeGCM, PNPushTypeAPNS2, PNPushTypeFCM.
TopicstringYes if PNPushType is PNPushTypeAPNS2Not setNotifications topic name (usually it is application's bundle identifier).
EnvironmentPNPushEnvironmentNoPNPushEnvironmentDevelopmentWorks only if PNPushType set to PNPushTypeAPNS2. Accepted values: PNPushEnvironmentDevelopment, PNPushEnvironmentProduction.
QueryParammap[string]stringOptionalQueryParam 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

Adding Device to Channel

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

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

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.

Listing Channels For Device

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.

Description

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

pn. ListPushProvisions().DeviceIDForPush(string).PushType(PNPushTypeGCM| PNPushTypeAPNS2).Topic(string).Environment(PNPushEnvironment).QueryParam(map[string]string).Execute()
ParameterTypeRequiredDefaultDescription
DeviceIDForPushstringYesDevice ID.
PushTypePNPushTypeGCM
PNPushTypeAPNS2
PNPushTypeFCM
YesNot setAccepted values: PNPushTypeGCM, PNPushTypeAPNS2, PNPushTypeFCM.
TopicstringYes if PNPushType is PNPushTypeAPNS2Not setNotifications topic name (usually it is application's bundle identifier).
EnvironmentPNPushEnvironmentNoPNPushEnvironmentDevelopmentWorks only if PNPushType set to PNPushTypeAPNS2. Accepted values: PNPushEnvironmentDevelopment, PNPushEnvironmentProduction.
QueryParammap[string]stringOptionalQueryParam 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

Listing 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:

MethodTypeDescription
Channels[]stringList of channels associated for push notifications.

Removing Device From Channel

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.

Description

Disable 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 V4 SDK:

pn. RemovePushNotificationsFromChannels().Channels([]string).DeviceIDForPush(string).PushType(PNPushTypeGCM|PNPushTypeAPNS2).Topic(string).Environment(PNPushEnvironment).QueryParam(map[string]string).Execute()
ParameterTypeRequiredDefaultDescription
Channels[]stringYeschannels to add to the channel group
DeviceIDForPushstringYesDevice ID.
PushTypePNPushTypeGCM
PNPushTypeAPNS
PNPushTypeAPNS2
PNPushTypeFCM
YesNot setAccepted values: PNPushTypeGCM, PNPushTypeAPNS2, PNPushTypeFCM.
TopicstringYes if PNPushType is PNPushTypeAPNS2Not setNotifications topic name (usually it is application's bundle identifier).
EnvironmentPNPushEnvironmentNoPNPushEnvironmentDevelopmentWorks only if PNPushType set to PNPushTypeAPNS2. Accepted values: PNPushEnvironmentDevelopment, PNPushEnvironmentProduction.
QueryParammap[string]stringOptionalQueryParam 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

Removing 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 push notifications

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.

Description

Disable push notifications from all channels registered with the specified pushToken.

Method(s)

To run Remove all push notifications you can use the following method(s) in the Go V4 SDK:

pn.RemoveAllPushNotifications().DeviceIDForPush(string).PushType(PNPushTypeGCM| PNPushTypeAPNS2).Topic(string).Environment(PNPushEnvironment).QueryParam(map[string]string).Execute()
ParameterTypeRequiredDefaultDescription
DeviceIDForPushstringYesDevice ID.
PushTypePNPushTypeGCM
PNPushTypeAPNS
PNPushTypeAPNS2
PNPushTypeFCM
YesNot setAccepted values: PNPushTypeGCM, PNPushTypeAPNS2, PNPushTypeFCM.
TopicstringYes if PNPushType is PNPushTypeAPNS2Not setNotifications topic name (usually it is application's bundle identifier).
EnvironmentPNPushEnvironmentNoPNPushEnvironmentDevelopmentWorks only if PNPushType set to PNPushTypeAPNS2. Accepted values: PNPushEnvironmentDevelopment, PNPushEnvironmentProduction.
QueryParammap[string]stringOptionalQueryParam 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 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