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>)
PushTyperequired#- Accepted values:
PNPushType.FCM,PNPushType.APNS2. Channelsrequired#- Channels to enable for push notifications.
DeviceIdrequired#- Device token.
Environment#- APNs environment (APNS2 only).
Topic#- APNs topic (bundle identifier) (APNS2 only).
QueryParam#- Optional query parameters for debugging.
Deprecated#AsyncPNCallbackof typePNPushAddChannelResult.Executerequired#System.Actionof typePNPushAddChannelResult.ExecuteAsync#- 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 linesReturns
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>)
DeviceIdrequired#- Device token.
PushTyperequired#- Accepted values:
PNPushType.FCM,PNPushType.APNS2. Environment#- APNs environment (APNS2 only).
Topic#- APNs topic (bundle identifier) (APNS2 only).
QueryParam#- Optional query parameters for debugging.
Deprecated#AsyncPNCallbackof typePNPushListProvisionsResult.Executerequired#System.Actionof typePNPushListProvisionsResult.ExecuteAsync#- 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 linesReturns
The AuditPushChannelProvisions() operation returns a PNPushListProvisionsResult which contains the following property:
| Property Name | Type | Description |
|---|---|---|
Channels | List<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>)
DeviceIdrequired#- Device token.
Channelsrequired#- Channels to disable for push notifications.
PushTyperequired#- Accepted values:
PNPushType.FCM,PNPushType.APNS2. Environment#- APNs environment (APNS2 only).
Topic#- APNs topic (bundle identifier) (APNS2 only).
QueryParam#- 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 linesReturns
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>)
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 linesReturns
The RemoveAllPushNotificationsFromDeviceWithPushToken() operation returns a PNPushRemoveAllChannelsResult and PNStatus.