Mobile Push Notifications API for PubNub Unity 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 provided set of channels.

Method(s)

To run Adding Device to Channel you can use the following method(s) in the Unity SDK:

pubnub.AddPushNotificationsOnChannels()
.PushType(PNPushType)
.Channels(Array)
.DeviceId(string)
.Environment(PushEnvironment)
.Topic(string)
.QueryParam(Dictionary<string,object>)
.Execute(System.Action<PNPushAddChannelResult, PNStatus>)
ParameterTypeRequiredDescription
PushTypePNPushTypeYesAccepted values: PNPushType.GCM, PNPushType.FCM, PNPushType.APNS2.
ChannelsArrayYesAdd mobile push notifications on the specified Channels.
DeviceIdstringYesDevice ID.
EnvironmentPushEnvironmentAPNs2 onlyPNPushType.APNS2 only. Apple APNs server (refer to this Apple document) to contact. Valid values are Development and Production.
TopicstringAPNs2 onlyPNPushType.APNS2 only. Notification topic name (usually the application's bundle identifier).
QueryParamDictionary<string, object>OptionalDictionary object to pass name/value pairs as query string params with PubNub URL request for debug purpose.
AsyncPNCallbackDeprecatedPNCallback of type PNPushAddChannelResult.
ExecuteSystem.ActionYesSystem.Action of type PNPushAddChannelResult.
ExecuteAsyncNoneOptionalReturns Task<PNResult<PNPushAddChannelResult>>.

Basic Usage

Add Device to Channel

// for FCM/GCM
pubnub.AddPushNotificationsOnChannels()
.PushType(PNPushType.GCM)
.Channels(new string[] {
"ch1",
"ch2",
"ch3"
})
.DeviceId("googleDevice")
.Execute((result, status) => {});

// for APNS2
pubnub.AddPushNotificationsOnChannels()
.PushType(PNPushType.APNS2)
.Channels(new string[] {
show all 23 lines

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

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

pubnub.AuditPushChannelProvisions()
.DeviceId(string)
.PushType(PNPushType)
.Environment(PushEnvironment)
.Topic(string)
.QueryParam(Dictionary<string,object>)
.Execute(System.Action<PNPushListProvisionsResult, PNStatus>)
ParameterTypeRequiredDescription
DeviceIdstringYesDevice ID.
PushTypePNPushTypeYesAccepted values: PNPushType.GCM, PNPushType.FCM, PNPushType.APNS2.
EnvironmentPushEnvironmentAPNs2 onlyPNPushType.APNS2 only. Apple APNs server (refer to this Apple document) to contact. Valid values are Development and Production.
TopicstringAPNs2 onlyPNPushType.APNS2 only. Notification topic name (usually the application's bundle identifier).
QueryParamDictionary<string, object>OptionalDictionary object to pass name/value pairs as query string params with PubNub URL request for debug purpose.
AsyncPNCallbackDeprecatedPNCallback of type PNPushListProvisionsResult.
ExecuteSystem.ActionYesSystem.Action of type PNPushListProvisionsResult.
ExecuteAsyncNoneOptionalReturns Task<PNResult<PNPushListProvisionsResult>>.

Basic Usage

List Channels For Device

// for FCM/GCM
pubnub.AuditPushChannelProvisions()
.DeviceId("googleDevice")
.PushType(PNPushType.GCM)
.Execute((result, status) => {});

// for APNS2
pubnub.AuditPushChannelProvisions()
.DeviceId("appleDevice")
.PushType(PNPushType.APNS2)
.Topic("myapptopic")
.Environment(PushEnvironment.Development)
.Execute((result, status) => {});

Returns

The AuditPushChannelProvisions() operation returns a PNPushListProvisionsResult which contains the following property:

Property NameTypeDescription
ChannelsList<string>List 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 provided set of channels.

Method(s)

To run Removing Device From Channel you can use the following method(s) in the Unity SDK:

pubnub.RemovePushNotificationsFromChannels()
.DeviceId(string)
.Channels(Array)
.PushType(PNPushType)
.Environment(PushEnvironment)
.Topic(string)
.QueryParam(Dictionary<string,object>)
ParameterTypeRequiredDescription
DeviceIdstringYesDevice ID.
ChannelsArrayYesRemove mobile push notifications on the specified Channels.
PushTypePNPushTypeYesAccepted values: PNPushType.GCM, PNPushType.FCM, PNPushType.APNS2.
EnvironmentPushEnvironmentAPNs2 onlyPNPushType.APNS2 only. Apple APNs server (refer to this Apple document) to contact. Valid values are Development and Production.
TopicstringAPNs2 onlyPNPushType.APNS2 only. Notification topic name (usually the application's bundle identifier).
QueryParamDictionary<string, object>OptionalDictionary object to pass name/value pairs as query string params with PubNub URL request for debug purpose.
AsyncPNCallbackDeprecatedPNCallback of type PNPushRemoveChannelResult.
ExecutePNCallbackYesPNCallback of type PNPushRemoveChannelResult.
ExecuteAsyncNoneOptionalReturns Task<PNResult<PNPushRemoveChannelResult>>.

Basic Usage

Remove Device From Channel

// for FCM/GCM
pubnub.RemovePushNotificationsFromChannels()
.DeviceId("googleDevice")
.Channels(new string[] {
"ch1",
"ch2",
"ch3"
})
.PushType(PNPushType.GCM)
.Execute((result, status) => {});

// for APNS2
pubnub.RemovePushNotificationsFromChannels()
.DeviceId("appleDevice")
.Channels(new string[] {
show all 23 lines

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

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

pubnub.RemoveAllPushNotificationsFromDeviceWithPushToken()
.DeviceId(string)
.PushType(PNPushType)
.Environment(PushEnvironment)
.Topic(string)
.QueryParam(Dictionary<string,object>)
.Execute(System.Action<PNPushRemoveAllChannelsResult, PNStatus>)
ParameterTypeRequiredDescription
DeviceIdstringYesDevice ID
PushTypePNPushTypeYesAccepted values: PNPushType.GCM, PNPushType.FCM, PNPushType.APNS2.
EnvironmentPushEnvironmentAPNs2 onlyPNPushType.APNS2 only. Apple APNs server (refer to this Apple document) to contact. Valid values are Development and Production.
TopicstringAPNs2 onlyPNPushType.APNS2 only. Notification topic name (usually the application's bundle identifier).
QueryParamDictionary<string, object>OptionalDictionary object to pass name/value pairs as query string params with PubNub URL request for debug purpose.
AsyncPNCallbackDeprecatedPNCallback of type PNPushRemoveAllChannelsResult.
ExecutePNCallbackYesPNCallback of type PNPushRemoveAllChannelsResult.
ExecuteAsyncNoneOptionalReturns Task<PNResult<PNPushRemoveAllChannelsResult>>.

Basic Usage

Remove all mobile push notifications

// for FCM/GCM
pubnub.RemoveAllPushNotificationsFromDeviceWithPushToken()
.DeviceId("googleDevice")
.PushType(PNPushType.GCM)
.Execute(new PNPushRemoveAllChannelsResultExt((r, s) => {
Debug.Log(pubnub.JsonPluggableLibrary.SerializeToJsonString(r));
}));

// for APNS2
pubnub.RemoveAllPushNotificationsFromDeviceWithPushToken()
.DeviceId("appleDevice")
.PushType(PNPushType.APNS2)
.Topic("myapptopic")
.Environment(PushEnvironment.Development)
.Execute(new PNPushRemoveAllChannelsResultExt((r, s) => {
show all 17 lines

Returns

The RemoveAllPushNotificationsFromDeviceWithPushToken() operation returns a PNPushRemoveAllChannelsResult which contains the following property:

Property NameTypeDescription
PNPushRemoveAllChannelsResultObjectReturns empty object.
PNStatusObjectReturns status of request if error occurred or not.
Last updated on