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.

Adding Device to Channel

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.

Description

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

pubnub.AddPushNotificationsOnChannels().Channels(List<string>).DeviceID(string).PushType(PNPushType).QueryParam(Dictionary<string,string>).Async(result, status)
ParameterTypeRequiredDefaultDescription
ChannelsList<string>YesAdd mobile push notifications on the specified channels.
DeviceIdstringYesDevice ID.
PushTypePNPushTypeYesNot setAccepted values: PNPushType.GCM, PNPushType.APNS2.
TopicstringYes if PNPushType is APNS2Not setNotifications topic name (usually it is application's bundle identifier).
EnvironmentPNPushEnvironmentNoDevelopmentWorks only if PNPushType set to APNS2. Accepted values: Development, Production.
QueryParamDictionary<string, string>OptionalQueryParam accepts a Dictionary object, the keys and values are passed as the query string parameters of the URL called by the API.
AsyncPNCallbackYesPNCallback of type PNPushAddChannelResult.

Basic Usage

Adding Device to Channel

// for FCM/GCM
pubnub.AddPushNotificationsOnChannels()
.Channels(new List<string>{"channel2"})
.DeviceID(<deviceId>)
.PushType(PNPushType.GCM)
.Async((result, status) => {
Debug.Log ("in AddPushNotificationsOnChannels");
if(status.Error){
Debug.Log (string.Format(" AddPushNotificationsOnChannels Error: {0} {1} {2}", status.StatusCode, status.ErrorData, status.Category));
} else {
Debug.Log (string.Format("DateTime {0}, In AddPushNotificationsOnChannels, result: {1}", DateTime.UtcNow, result.Message));
}
});

// for APNS2
show all 29 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().

Listing Channels For Device

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.

Description

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

pubnub.AuditPushChannelProvisions().DeviceID(string).PushType(PNPushType).Topic(string).Environment(PNPushEnvironment).QueryParam(Dictionary<string,string>).Async(result, status)
ParameterTypeRequiredDefaultDescription
DeviceIDstringYesDevice ID.
PushTypePNPushTypeYesNot setAccepted values: PNPushType.GCM, PNPushType.APNS2.
TopicstringYes if PNPushType is APNS2Not setNotifications topic name (usually it is application's bundle identifier).
EnvironmentPNPushEnvironmentNoDevelopmentWorks only if PNPushType set to APNS2. Accepted values: Development, Production.
QueryParamDictionary<string, string>OptionalQueryParam accepts a Dictionary object, the keys and values are passed as the query string parameters of the URL called by the API.
AsyncPNCallbackYesPNCallback of type PNPushAddChannelResult..

Basic Usage

Listing Channels For Device

// for FCM/GCM
pubnub.AuditPushChannelProvisions()
.DeviceID(<deviceId>)
.PushType(PNPushType.GCM)
.Async((result, status) => {
Debug.Log ("in AuditPushChannelProvisions");
if(status.Error){
Debug.Log (string.Format(" AuditPushChannelProvisions Error: {0} {1} {2}", status.StatusCode, status.ErrorData, status.Category));
} else {
Debug.Log (string.Format("DateTime {0}, In AuditPushChannelProvisions, result: {1}", DateTime.UtcNow, (result.Channels!=null)?string.Join(",", result.Channels.ToArray()):""));
}
});

// for APNS2
pubnub.AuditPushChannelProvisions()
show all 27 lines

Returns

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

MethodTypeDescription
ChannelsList<string>List of channels associated for mobile push notifications.

Removing Device From Channel

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.

Description

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

pubnub.RemovePushNotificationsFromChannels().Channels(List<string>).DeviceID(string).PushType(PNPushType).Topic(string).Environment(PNPushEnvironment).QueryParam(Dictionary<string,string>).Async()
ParameterTypeRequiredDefaultDescription
ChannelsList<string>YesRemove mobile push notifications on the specified channels.
DeviceIDstringYesDevice ID.
PushTypePNPushTypeYesNot setAccepted values: PNPushType.GCM, PNPushType.APNS2.
TopicstringYes if PNPushType is APNS2Not setNotifications topic name (usually it is application's bundle identifier).
EnvironmentPNPushEnvironmentNoDevelopmentWorks only if PNPushType set to APNS2. Accepted values: Development, Production.
QueryParamDictionary<string, string>OptionalQueryParam accepts a Dictionary object, the keys and values are passed as the query string parameters of the URL called by the API.
AsyncPNCallbackYesPNCallback of type PNPushAddChannelResult.

Basic Usage

Removing Device From Channel

// for FCM/GCM
pubnub.RemovePushNotificationsFromChannels()
.Channels(new List<string> {
"channel2"
})
.DeviceID(<deviceId>)
.PushType(PNPushType.GCM)
.Async((result, status) => {
Debug.Log ("in RemovePushNotificationsFromChannels");
if( status.Error ){
Debug.Log(string.Format(" RemovePushNotificationsFromChannels Error: {0} {1} {2}", status.StatusCode, status.ErrorData, status.Category));
} else {
}
});

show all 31 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

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.

Description

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

pubnub.RemoveAllPushNotifications().DeviceID(string).PushType(PNPushType).Topic(string).Environment(PNPushEnvironment).QueryParam(Dictionary<string,string>).Async()
ParameterTypeRequiredDefaultDescription
DeviceIDstringYesDevice ID.
PushTypePNPushTypeYesNot setAccepted values: PNPushType.GCM, PNPushType.APNS2.
TopicstringYes if PNPushType is APNS2Not setNotifications topic name (usually it is application's bundle identifier).
EnvironmentPNPushEnvironmentNoDevelopmentWorks only if PNPushType set to APNS2. Accepted values: Development, Production.
QueryParamDictionary<string, string>OptionalQueryParam accepts a Dictionary object, the keys and values are passed as the query string parameters of the URL called by the API.
AsyncPNCallbackYesPNCallback of type PNPushRemoveAllChannelsResult.

Basic Usage

Remove all mobile push notifications

// for FCM/GCM
pubnub.RemoveAllPushNotifications()
.DeviceID(<deviceId>)
.PushType(PNPushType.GCM)
.Async((result, status) => {
Debug.Log ("in RemoveAllPushNotificationsFromChannels");
if(status.Error){
Debug.Log (string.Format("In Example, RemoveAllPushNotificationsFromChannels Error: {0} {1} {2}", status.StatusCode, status.ErrorData, status.Category));
} else {
Debug.Log (string.Format("DateTime {0}, In RemoveAllPushNotificationsFromChannels, result: {1}", DateTime.UtcNow, result.Message));
}
});

// for APNS2
pubnub.RemoveAllPushNotifications()
show all 27 lines

Returns

The RemoveAllPushNotificationsFromDeviceWithPushToken() does not return actionable data, be sure to check the status object on the outcome of the operation by checking the status.isError().

Last updated on