Mobile Push Notifications API for C# 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.
Request execution
We recommend using try
and catch
statements when working with the C# SDK.
If there's an issue with the provided API parameter values, like missing a required parameter, the SDK throws an exception. However, if there is a server-side API execution issue or a network problem, the error details are contained within the status
.
try
{
PNResult<PNPublishResult> publishResponse = await pubnub.Publish()
.Message("Why do Java developers wear glasses? Because they can't C#.")
.Channel("my_channel")
.ExecuteAsync();
PNStatus status = publishResponse.Status;
Console.WriteLine("Server status code : " + status.StatusCode.ToString());
}
catch (Exception ex)
{
Console.WriteLine($"Request can't be executed due to error: {ex.Message}");
}
Add 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.
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 C# SDK:
pubnub.AddPushNotificationsOnChannels()
.PushType(PNPushType)
.Channels(Array)
.DeviceId(string)
.Environment(PushEnvironment)
.Topic(string)
.QueryParam(Dictionary<string,object>)
Parameter | Description |
---|---|
PushType *Type: PNPushType | Accepted values: PNPushType.GCM , PNPushType.FCM , PNPushType.APNS2 . |
Channels *Type: Array | Add mobile push notifications on the specified Channels . |
DeviceId *Type: string | Device ID. |
Environment Type: PushEnvironment | PNPushType.APNS2 only. Apple APNs server (refer to this Apple document) to contact. Valid values are Development and Production. |
Topic Type: string | PNPushType.APNS2 only. Notification topic name (usually the application's bundle identifier). |
QueryParam Type: Dictionary <string, object> | Dictionary object to pass name/value pairs as query string params with PubNub URL request for debug purpose. |
Async Type: | PNCallback of type PNPushAddChannelResult .This parameter is deprecated and will be removed in a future version. Please use the ExecuteAsync parameter instead. |
Execute *Type: PNCallback | PNCallback of type PNPushAddChannelResult . |
ExecuteAsync Type: None | Returns PNResult<PNPushAddChannelResult> . |
Basic Usage
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.
Add Device to Channel
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()
.
List 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.
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 C# SDK:
pubnub.AuditPushChannelProvisions()
.DeviceId(string)
.PushType(PNPushType)
.Environment(PushEnvironment)
.Topic(string)
.QueryParam(Dictionary<string,object>)
Parameter | Description |
---|---|
DeviceId *Type: string | Device ID. |
PushType *Type: PNPushType | Accepted values: PNPushType.GCM , PNPushType.FCM , PNPushType.APNS2 . |
Environment Type: PushEnvironment | PNPushType.APNS2 only. Apple APNs server (refer to this Apple document) to contact. Valid values are Development and Production. |
Topic Type: string | PNPushType.APNS2 only. Notification topic name (usually the application's bundle identifier). |
QueryParam Type: Dictionary <string, object> | Dictionary object to pass name/value pairs as query string params with PubNub URL request for debug purpose. |
Async Type: | PNCallback of type PNPushListProvisionsResult .This parameter is deprecated and will be removed in a future version. Please use the ExecuteAsync parameter instead. |
Execute *Type: PNCallback | PNCallback of type PNPushListProvisionsResult . |
ExecuteAsync Type: None | Returns PNResult<PNPushListProvisionsResult> . |
Basic Usage
List Channels For Device
Returns
The AuditPushChannelProvisions()
operation returns a PNPushListProvisionsResult
which contains the following property:
Property Name | Type | Description |
---|---|---|
Channels | List<string> | List of channels associated for mobile push notifications. |
Remove 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.
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 C# SDK:
pubnub.RemovePushNotificationsFromChannels()
.DeviceId(string)
.Channels(Array)
.PushType(PNPushType)
.Environment(PushEnvironment)
.Topic(string)
.QueryParam(Dictionary<string,object>)
Parameter | Description |
---|---|
DeviceId *Type: string | Device ID. |
Channels *Type: Array | Remove mobile push notifications on the specified Channels . |
PushType *Type: PNPushType | Accepted values: PNPushType.GCM , PNPushType.FCM , PNPushType.APNS2 . |
Environment Type: PushEnvironment | PNPushType.APNS2 only. Apple APNs server (refer to this Apple document) to contact. Valid values are Development and Production. |
Topic Type: string | PNPushType.APNS2 only. Notification topic name (usually the application's bundle identifier). |
QueryParam Type: Dictionary <string, object> | Dictionary object to pass name/value pairs as query string params with PubNub URL request for debug purpose. |
Async Type: | PNCallback of type PNPushRemoveChannelResult .This parameter is deprecated and will be removed in a future version. Please use the ExecuteAsync parameter instead. |
Execute *Type: PNCallback | PNCallback of type PNPushRemoveChannelResult . |
ExecuteAsync Type: None | Returns PNResult<PNPushRemoveChannelResult> . |
Basic Usage
Remove Device From Channel
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.
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 C# SDK:
pubnub.RemoveAllPushNotificationsFromDeviceWithPushToken()
.DeviceId(string)
.PushType(PNPushType)
.Environment(PushEnvironment)
.Topic(string)
.QueryParam(Dictionary<string,object>)
Parameter | Description |
---|---|
DeviceId *Type: string | Device ID |
PushType *Type: PNPushType | Accepted values: PNPushType.GCM , PNPushType.FCM , PNPushType.APNS2 . |
Environment Type: PushEnvironment | PNPushType.APNS2 only. Apple APNs server (refer to this Apple document) to contact. Valid values are Development and Production. |
Topic Type: string | PNPushType.APNS2 only. Notification topic name (usually the application's bundle identifier). |
QueryParam Type: Dictionary <string, object> | Dictionary object to pass name/value pairs as query string params with PubNub URL request for debug purpose. |
Async Type: | PNCallback of type PNPushRemoveAllChannelsResult .This parameter is deprecated and will be removed in a future version. Please use the ExecuteAsync parameter instead. |
Execute *Type: PNCallback | PNCallback of type PNPushRemoveAllChannelsResult . |
ExecuteAsync Type: None | Returns PNResult<PNPushRemoveAllChannelsResult> . |
Basic Usage
Remove all mobile push notifications
Returns
The RemoveAllPushNotificationsFromDeviceWithPushToken()
operation returns a PNPushRemoveAllChannelsResult
which contains the following property:
Property Name | Type | Description |
---|---|---|
PNPushRemoveAllChannelsResult | Object | Returns empty object. |
PNStatus | Object | Returns status of request if error occurred or not. |