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

Add 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.

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()
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

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:

MethodTypeDescription
Channels[]stringList 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()
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

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()
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 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