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)
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
Channels | List<string> | Yes | Add mobile push notifications on the specified channels . | |
DeviceId | string | Yes | Device ID. | |
PushType | PNPushType | Yes | Not set | Accepted values: PNPushType.GCM , PNPushType.APNS2 . |
Topic | string | Yes if PNPushType is APNS2 | Not set | Notifications topic name (usually it is application's bundle identifier). |
Environment | PNPushEnvironment | No | Development | Works only if PNPushType set to APNS2 . Accepted values: Development , Production . |
QueryParam | Dictionary<string, string> | Optional | QueryParam accepts a Dictionary object, the keys and values are passed as the query string parameters of the URL called by the API. | |
Async | PNCallback | Yes | PNCallback 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 linesReturns
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)
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
DeviceID | string | Yes | Device ID. | |
PushType | PNPushType | Yes | Not set | Accepted values: PNPushType.GCM , PNPushType.APNS2 . |
Topic | string | Yes if PNPushType is APNS2 | Not set | Notifications topic name (usually it is application's bundle identifier). |
Environment | PNPushEnvironment | No | Development | Works only if PNPushType set to APNS2 . Accepted values: Development , Production . |
QueryParam | Dictionary<string, string> | Optional | QueryParam accepts a Dictionary object, the keys and values are passed as the query string parameters of the URL called by the API. | |
Async | PNCallback | Yes | PNCallback 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 linesReturns
The AuditPushChannelProvisions()
operation returns a PNPushListProvisionsResult
which contains the following operations:
Method | Type | Description |
---|---|---|
Channels | List<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()
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
Channels | List<string> | Yes | Remove mobile push notifications on the specified channels . | |
DeviceID | string | Yes | Device ID. | |
PushType | PNPushType | Yes | Not set | Accepted values: PNPushType.GCM , PNPushType.APNS2 . |
Topic | string | Yes if PNPushType is APNS2 | Not set | Notifications topic name (usually it is application's bundle identifier). |
Environment | PNPushEnvironment | No | Development | Works only if PNPushType set to APNS2 . Accepted values: Development , Production . |
QueryParam | Dictionary<string, string> | Optional | QueryParam accepts a Dictionary object, the keys and values are passed as the query string parameters of the URL called by the API. | |
Async | PNCallback | Yes | PNCallback 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 linesReturns
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()
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
DeviceID | string | Yes | Device ID. | |
PushType | PNPushType | Yes | Not set | Accepted values: PNPushType.GCM , PNPushType.APNS2 . |
Topic | string | Yes if PNPushType is APNS2 | Not set | Notifications topic name (usually it is application's bundle identifier). |
Environment | PNPushEnvironment | No | Development | Works only if PNPushType set to APNS2 . Accepted values: Development , Production . |
QueryParam | Dictionary<string, string> | Optional | QueryParam accepts a Dictionary object, the keys and values are passed as the query string parameters of the URL called by the API. | |
Async | PNCallback | Yes | PNCallback 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 linesReturns
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()
.