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​

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:

1pubnub.AddPushNotificationsOnChannels()
2 .PushType(PNPushType)
3 .Channels(Array)
4 .DeviceId(string)
5 .Environment(PushEnvironment)
6 .Topic(string)
7 .QueryParam(Dictionary<string,object>)
8 .Execute(System.Action<PNPushAddChannelResult, PNStatus>)
* required
ParameterDescription
PushType *
Type: PNPushType
Accepted values: 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.
1

Returns​

The AddPushNotificationsOnChannels() does not return actionable data. Check status.isError() 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.

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

Method(s)​

Use the following method(s) in the Unity SDK:

1pubnub.AuditPushChannelProvisions()
2 .DeviceId(string)
3 .PushType(PNPushType)
4 .Environment(PushEnvironment)
5 .Topic(string)
6 .QueryParam(Dictionary<string,object>)
7 .Execute(System.Action<PNPushListProvisionsResult, PNStatus>)
* required
ParameterDescription
DeviceId *
Type: string
Device token.
PushType *
Type: PNPushType
Accepted values: 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​

1

Returns​

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

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

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

Method(s)​

Use the following method(s) in the Unity SDK:

1pubnub.RemovePushNotificationsFromChannels()
2 .DeviceId(string)
3 .Channels(Array)
4 .PushType(PNPushType)
5 .Environment(PushEnvironment)
6 .Topic(string)
7 .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.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​

1

Returns​

The RemovePushNotificationsFromChannels() does not return actionable data. Check status.isError() 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 mobile push notifications from all channels registered with the specified device token.

Method(s)​

Use the following method(s) in the Unity SDK:

1pubnub.RemoveAllPushNotificationsFromDeviceWithPushToken()
2 .DeviceId(string)
3 .PushType(PNPushType)
4 .Environment(PushEnvironment)
5 .Topic(string)
6 .QueryParam(Dictionary<string,object>)
7 .Execute(System.Action<PNPushRemoveAllChannelsResult, PNStatus>)
* required
ParameterDescription
DeviceId *
Type: string
Device token.
PushType *
Type: PNPushType
Accepted values: 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​

1

Returns​

The RemoveAllPushNotificationsFromDeviceWithPushToken() operation returns a PNPushRemoveAllChannelsResult and PNStatus.

Was this page useful?

Last updated on