Mobile Push Notifications API for C# 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.
Request execution
Use try
/catch
when working with the C# SDK.
If a request has invalid parameters (for example, a missing required field), the SDK throws an exception. If the request reaches the server but fails (server error or network issue), the error details are available in the returned 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 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)
pubnub.AddPushNotificationsOnChannels()
.PushType(PNPushType)
.Channels(Array)
.DeviceId(string)
.Environment(PushEnvironment)
.Topic(string)
.QueryParam(Dictionary<string,object>)
Parameter | Description |
---|---|
PushType *Type: PNPushType | Push type. One of: PNPushType.GCM , PNPushType.FCM , PNPushType.APNS2 . |
Channels *Type: Array | Channels to enable for push notifications. |
DeviceId *Type: string | Device ID (push token). |
Environment Type: PushEnvironment | APNs environment (Development , Production ). |
Topic Type: string | APNs topic (bundle identifier). |
QueryParam Type: Dictionary <string, object> | Name/value pairs to send as query parameters. |
Async Type: | ExecuteAsync . |
Execute *Type: PNCallback | Callback of type PNPushAddChannelResult . |
ExecuteAsync Type: None | Returns PNResult<PNPushAddChannelResult> . |
Sample code
Reference code
Add device to channel
Returns
No payload is returned. 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.
Get all channels with push notifications for the specified push token.
Method(s)
pubnub.AuditPushChannelProvisions()
.DeviceId(string)
.PushType(PNPushType)
.Environment(PushEnvironment)
.Topic(string)
.QueryParam(Dictionary<string,object>)
Parameter | Description |
---|---|
DeviceId *Type: string | Device ID (push token). |
PushType *Type: PNPushType | Push type. One of: PNPushType.GCM , PNPushType.FCM , PNPushType.APNS2 . |
Environment Type: PushEnvironment | APNs environment (Development , Production ). |
Topic Type: string | APNs topic (bundle identifier). |
QueryParam Type: Dictionary <string, object> | Name/value pairs to send as query parameters. |
Async Type: | ExecuteAsync . |
Execute *Type: PNCallback | Callback of type PNPushListProvisionsResult . |
ExecuteAsync Type: None | Returns PNResult<PNPushListProvisionsResult> . |
Sample code
List channels for device
Returns
Returns PNPushListProvisionsResult
with:
Property Name | Type | Description |
---|---|---|
Channels | List<string> | Channels associated with push notifications. |
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 push notifications on selected channels.
Method(s)
pubnub.RemovePushNotificationsFromChannels()
.DeviceId(string)
.Channels(Array)
.PushType(PNPushType)
.Environment(PushEnvironment)
.Topic(string)
.QueryParam(Dictionary<string,object>)
Parameter | Description |
---|---|
DeviceId *Type: string | Device ID (push token). |
Channels *Type: Array | Channels to disable for push notifications. |
PushType *Type: PNPushType | Push type. One of: PNPushType.GCM , PNPushType.FCM , PNPushType.APNS2 . |
Environment Type: PushEnvironment | APNs environment (Development , Production ). |
Topic Type: string | APNs topic (bundle identifier). |
QueryParam Type: Dictionary <string, object> | Name/value pairs to send as query parameters. |
Async Type: | ExecuteAsync . |
Execute *Type: PNCallback | Callback of type PNPushRemoveChannelResult . |
ExecuteAsync Type: None | Returns PNResult<PNPushRemoveChannelResult> . |
Sample code
Remove device from channel
Returns
No payload is returned. 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 push notifications from all channels registered for the specified push token.
Method(s)
pubnub.RemoveAllPushNotificationsFromDeviceWithPushToken()
.DeviceId(string)
.PushType(PNPushType)
.Environment(PushEnvironment)
.Topic(string)
.QueryParam(Dictionary<string,object>)
Parameter | Description |
---|---|
DeviceId *Type: string | Device ID (push token). |
PushType *Type: PNPushType | Push type. One of: PNPushType.GCM , PNPushType.FCM , PNPushType.APNS2 . |
Environment Type: PushEnvironment | APNs environment (Development , Production ). |
Topic Type: string | APNs topic (bundle identifier). |
QueryParam Type: Dictionary <string, object> | Name/value pairs to send as query parameters. |
Async Type: | ExecuteAsync . |
Execute *Type: PNCallback | Callback of type PNPushRemoveAllChannelsResult . |
ExecuteAsync Type: None | Returns PNResult<PNPushRemoveAllChannelsResult> . |
Sample code
Remove all mobile push notifications
Returns
Returns PNPushRemoveAllChannelsResult
with:
Property Name | Type | Description |
---|---|---|
PNPushRemoveAllChannelsResult | Object | Empty object on success. |
PNStatus | Object | Request status (error or success). |