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
PushType required#
Type: PNPushType
Accepted values: PNPushType.FCM, PNPushType.APNS2.
Channels required#
Type: Array
Channels to enable for push notifications.
DeviceId required#
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.
AsyncDeprecated#
Type: PNCallback
PNCallback of type PNPushAddChannelResult.
Execute required#
Type: System.Action
System.Action of type PNPushAddChannelResult.
ExecuteAsync#
Type: None
Returns Task<PNResult<PNPushAddChannelResult>>.

Sample code​

Add device to channel​

1using PubnubApi;
2using PubnubApi.Unity;
3using UnityEngine;
4
5public class AddPushNotificationsExample : MonoBehaviour {
6 // Reference to a pubnub manager previously setup in Unity Editor
7 // For more details, see https://www.pubnub.com/docs/sdks/unity#configure-pubnub
8 [SerializeField] private PNManagerBehaviour pubnubManager;
9
10 // An editor-serialized array for the channels to add notifications
11 [SerializeField] private string[] channels = { "ch1", "ch2", "ch3" };
12
13 // An editor-serialized string for the device IDs
14 [SerializeField] private string fcmDeviceId = "googleDevice";
15 [SerializeField] private string apnsDeviceId = "appleDevice";
show all 62 lines

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
DeviceId required#
Type: string
Device token.
PushType required#
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.
AsyncDeprecated#
Type: PNCallback
PNCallback of type PNPushListProvisionsResult.
Execute required#
Type: System.Action
System.Action of type PNPushListProvisionsResult.
ExecuteAsync#
Type: None
Returns Task<PNResult<PNPushListProvisionsResult>>.

Sample code​

List channels for device​

1// Configuration
2PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
3{
4 SubscribeKey = "demo",
5 PublishKey = "demo",
6 Secure = true
7};
8
9// Initialize PubNub
10Pubnub pubnub = PubnubUnityUtils.NewUnityPubnub(pnConfiguration);
11
12// If you're using Unity Editor setup you can get the Pubnub instance from PNManagerBehaviour
13// For more details, see https://www.pubnub.com/docs/sdks/unity#configure-pubnub
14/*
15[SerializeField] private PNManagerBehaviour pubnubManager;
show all 37 lines

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
DeviceId required#
Type: string
Device token.
Channels required#
Type: Array
Channels to disable for push notifications.
PushType required#
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// Configuration
2PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
3{
4 SubscribeKey = "demo",
5 PublishKey = "demo",
6 Secure = true
7};
8
9// Initialize PubNub
10Pubnub pubnub = PubnubUnityUtils.NewUnityPubnub(pnConfiguration);
11
12// If you're using Unity Editor setup you can get the Pubnub instance from PNManagerBehaviour
13// For more details, see https://www.pubnub.com/docs/sdks/unity#configure-pubnub
14/*
15[SerializeField] private PNManagerBehaviour pubnubManager;
show all 47 lines

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
DeviceId required#
Type: string
Device token.
PushType required#
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// Configuration
2PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
3{
4 SubscribeKey = "demo",
5 PublishKey = "demo",
6 Secure = true
7};
8
9// Initialize PubNub
10Pubnub pubnub = PubnubUnityUtils.NewUnityPubnub(pnConfiguration);
11
12// If you're using Unity Editor setup you can get the Pubnub instance from PNManagerBehaviour
13// For more details, see https://www.pubnub.com/docs/sdks/unity#configure-pubnub
14/*
15[SerializeField] private PNManagerBehaviour pubnubManager;
show all 35 lines

Returns​

The RemoveAllPushNotificationsFromDeviceWithPushToken() operation returns a PNPushRemoveAllChannelsResult and PNStatus.

Was this page useful?

Last updated on