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

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>)
* required
ParameterDescription
PushType *
Type: PNPushType
Accepted values: PNPushType.GCM, PNPushType.FCM, PNPushType.APNS2.
Channels *
Type: Array
Channels to enable for push notifications.
DeviceId *
Type: string
Device token.
Environment
Type: PushEnvironment
APNs environment (APNS2 only).
Topic
Type: string
APNs topic (bundle identifier) (APNS2 only).
QueryParam
Type: Dictionary<string, object>
Optional query parameters for debugging.
Async
Type: PNCallback
PNCallback of type PNPushAddChannelResult.
Execute *
Type: System.Action
System.Action of type PNPushAddChannelResult.
ExecuteAsync
Type: None
Returns Task<PNResult<PNPushAddChannelResult>>.

Sample code

Add device to channel

Reference code
This example is a self-contained code snippet ready to be run. It includes necessary imports and executes methods with console logging. Use it as a reference when working with other examples in this document.

Returns

The AddPushNotificationsOnChannels() does not return actionable data. Check status.isError() on the status object.

List push notifications channels for a device

note
Requires Mobile Push Notifications add-on

Enable Mobile Push Notifications for your key in the Admin Portal. See how to enable add-on features.

List channels that have push notifications enabled for the specified device token.

Method(s)

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>)
* required
ParameterDescription
DeviceId *
Type: string
Device token.
PushType *
Type: PNPushType
Accepted values: PNPushType.GCM, PNPushType.FCM, PNPushType.APNS2.
Environment
Type: PushEnvironment
APNs environment (APNS2 only).
Topic
Type: string
APNs topic (bundle identifier) (APNS2 only).
QueryParam
Type: Dictionary<string, object>
Optional query parameters for debugging.
Async
Type: PNCallback
PNCallback of type PNPushListProvisionsResult.
Execute *
Type: System.Action
System.Action of type PNPushListProvisionsResult.
ExecuteAsync
Type: None
Returns Task<PNResult<PNPushListProvisionsResult>>.

Sample code

List channels for device


Returns

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

Property NameTypeDescription
Channels
List<string>
Channels with push notifications enabled.

Remove a device from push notifications channels

note
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 mobile push notifications on a set of channels.

Method(s)

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>)
* required
ParameterDescription
DeviceId *
Type: string
Device token.
Channels *
Type: Array
Channels to disable for push notifications.
PushType *
Type: PNPushType
Accepted values: PNPushType.GCM, PNPushType.FCM, PNPushType.APNS2.
Environment
Type: PushEnvironment
APNs environment (APNS2 only).
Topic
Type: string
APNs topic (bundle identifier) (APNS2 only).
QueryParam
Type: Dictionary<string, object>
Optional query parameters for debugging.

Sample code

Remove device from channel


Returns

The RemovePushNotificationsFromChannels() does not return actionable data. Check status.isError() on the status object.

Remove a device from all push notifications channels

note
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 mobile push notifications from all channels registered with the specified device token.

Method(s)

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>)
* required
ParameterDescription
DeviceId *
Type: string
Device token.
PushType *
Type: PNPushType
Accepted values: PNPushType.GCM, PNPushType.FCM, PNPushType.APNS2.
Environment
Type: PushEnvironment
APNs environment (APNS2 only).
Topic
Type: string
APNs topic (bundle identifier) (APNS2 only).
QueryParam
Type: Dictionary<string, object>
Optional query parameters for debugging.

Sample code

Remove all mobile push notifications


Returns

The RemoveAllPushNotificationsFromDeviceWithPushToken() operation returns a PNPushRemoveAllChannelsResult and PNStatus.

Last updated on