PubNub LogoDocs
SupportContact SalesLoginTry Our APIs

›API Reference

c-Sharp

  • Getting Started
  • API Reference

    • Configuration
    • Publish & Subscribe
    • Presence
    • Access Manager
    • Channel Groups
    • Message Persistence
    • Mobile Push
    • Objects
    • Files
    • Message Actions
    • Miscellaneous
  • Status Events
  • Troubleshooting
  • Change Log
  • Feature Support
  • Platform Support

Push Notifications API for PubNub C# SDK

PubNub's Mobile Push Gateway 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 Gateway, developers can eliminate the need for developing, configuring, and maintaining additional server-side components for third-party push notification providers.

Adding Device to Channel

Requires Mobile Push Notifications add-onRequires that you enable the Mobile Push Notifications for your key. Refer to the following page for details on enabling add-on features on your keys:
https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-

Description

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

pubnub.AddPushNotificationsOnChannels().PushType(PNPushType).Channels(Array).DeviceId(string).Environment(PushEnvironment).Topic(string).QueryParam(Dictionary<string,object>)
ParameterTypeRequiredDescription
PushTypePNPushTypeYesAccepted values: PNPushType.GCM, PNPushType.FCM, PNPushType.APNS2.
ChannelsArrayYesAdd push notifications on the specified Channels.
DeviceIdstringYesDevice ID.
EnvironmentPushEnvironmentAPNs2 onlyPNPushType.APNS2 only. Apple APNs server (refer to this Apple document) to contact. Valid values are Development and Production.
TopicstringAPNs2 onlyPNPushType.APNS2 only. Notification topic name (usually the application's bundle identifier).
QueryParamDictionary<string, object>OptionalDictionary object to pass name/value pairs as query string params with PubNub URL request for debug purpose.
AsyncPNCallbackDeprecatedPNCallback of type PNPushAddChannelResult.
ExecutePNCallbackYesPNCallback of type PNPushAddChannelResult.

Basic Usage

Adding Device to Channel:

// for FCM/GCM
pubnub.AddPushNotificationsOnChannels()
    .PushType(PNPushType.GCM)
    .Channels(new string[] {
        "ch1",
        "ch2",
        "ch3"
    })
    .DeviceId("googleDevice")
    .Execute(new DemoPushAddChannel());

public class DemoPushAddChannel : PNCallback<PNPushAddChannelResult> {
    public override void OnResponse(PNPushAddChannelResult result, PNStatus status) {
    }
}

// for APNS2
pubnub.AddPushNotificationsOnChannels()
    .PushType(PNPushType.APNS2)
    .Channels(new string[] {
        "ch1",
        "ch2",
        "ch3"
    })
    .DeviceId("appleDevice")
    .Topic("myapptopic")
    .Environment(PushEnvironment.Development)
    .Execute(new DemoPushAddChannel());

public class DemoPushAddChannel : PNCallback<PNPushAddChannelResult> {
    public override void OnResponse(PNPushAddChannelResult result, PNStatus status) {
    }
}

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-onRequires that you enable the Mobile Push Notifications for your key. Refer to the following page for details on enabling add-on features on your keys:
https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-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 C# V4 SDK:

pubnub.AuditPushChannelProvisions().DeviceId(string).PushType(PNPushType).Environment(PushEnvironment).Topic(string).QueryParam(Dictionary<string,object>)
ParameterTypeRequiredDescription
DeviceIdstringYesDevice ID.
PushTypePNPushTypeYesAccepted values: PNPushType.GCM, PNPushType.FCM, PNPushType.APNS2.
EnvironmentPushEnvironmentAPNs2 onlyPNPushType.APNS2 only. Apple APNs server (refer to this Apple document) to contact. Valid values are Development and Production.
TopicstringAPNs2 onlyPNPushType.APNS2 only. Notification topic name (usually the application's bundle identifier).
QueryParamDictionary<string, object>OptionalDictionary object to pass name/value pairs as query string params with PubNub URL request for debug purpose.
AsyncPNCallbackDeprecatedPNCallback of type PNPushListProvisionsResult.
ExecutePNCallbackYesPNCallback of type PNPushListProvisionsResult.

Basic Usage

Listing Channels For Device:

// for FCM/GCM
pubnub.AuditPushChannelProvisions()
    .DeviceId("googleDevice")
    .PushType(PNPushType.GCM)
    .Execute(new DemoPushListProvisionChannel());

public class DemoPushListProvisionChannel : PNCallback<PNPushListProvisionsResult> {
    public override void OnResponse(PNPushListProvisionsResult result, PNStatus status) {
    }
}

// for APNS2
pubnub.AuditPushChannelProvisions()
    .DeviceId("appleDevice")
    .PushType(PNPushType.APNS2)
    .Topic("myapptopic")
    .Environment(PushEnvironment.Development)
    .Execute(new DemoPushListProvisionChannel());

public class DemoPushListProvisionChannel : PNCallback<PNPushListProvisionsResult> {
    public override void OnResponse(PNPushListProvisionsResult result, PNStatus status) {
    }
}

Returns

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

Property NameTypeDescription
ChannelsListList of channels associated for push notifications.

Removing Device From Channel

Requires Mobile Push Notifications add-onRequires that you enable the Mobile Push Notifications for your key. Refer to the following page for details on enabling add-on features on your keys:
https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-

Description

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

pubnub.RemovePushNotificationsFromChannels().DeviceId(string).Channels(Array).PushType(PNPushType).Environment(PushEnvironment).Topic(string).QueryParam(Dictionary<string,object>)
ParameterTypeRequiredDescription
DeviceIdstringYesDevice ID.
ChannelsArrayYesRemove push notifications on the specified Channels.
PushTypePNPushTypeYesAccepted values: PNPushType.GCM, PNPushType.FCM, PNPushType.APNS2.
EnvironmentPushEnvironmentAPNs2 onlyPNPushType.APNS2 only. Apple APNs server (refer to this Apple document) to contact. Valid values are Development and Production.
TopicstringAPNs2 onlyPNPushType.APNS2 only. Notification topic name (usually the application's bundle identifier).
QueryParamDictionary<string, object>OptionalDictionary object to pass name/value pairs as query string params with PubNub URL request for debug purpose.
AsyncPNCallbackDeprecatedPNCallback of type PNPushRemoveChannelResult.
ExecutePNCallbackYesPNCallback of type PNPushRemoveChannelResult.

Basic Usage

Removing Device From Channel:

// for FCM/GCM
pubnub.RemovePushNotificationsFromChannels()
    .DeviceId("googleDevice")
    .Channels(new string[] {
        "ch1",
        "ch2",
        "ch3"
    })
    .PushType(PNPushType.GCM)
    .Execute(new DemoPushRemoveChannel());

public class DemoPushRemoveChannel : PNCallback<PNPushRemoveChannelResult> {
    public override void OnResponse(PNPushRemoveChannelResult result, PNStatus status) {
    }
}

// for APNS2
pubnub.RemovePushNotificationsFromChannels()
    .DeviceId("appleDevice")
    .Channels(new string[] {
        "ch1",
        "ch2",
        "ch3"
    })
    .PushType(PNPushType.APNS2)
    .Topic("myapptopic")
    .Environment(PushEnvironment.Development)
    .Execute(new DemoPushRemoveChannel());

public class DemoPushRemoveChannel : PNCallback<PNPushRemoveChannelResult> {
    public override void OnResponse(PNPushRemoveChannelResult result, PNStatus status) {
    }
}

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 push notifications

Requires Mobile Push Notifications add-onRequires that you enable the Mobile Push Notifications for your key. Refer to the following page for details on enabling add-on features on your keys:
https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-

Description

Disable push notifications from all channels registered with the specified pushToken.

Method(s)

To run Remove all push notifications you can use the following method(s) in the C# V4 SDK:

pubnub.RemoveAllPushNotificationsFromDeviceWithPushToken().DeviceId(string).PushType(PNPushType).Environment(PushEnvironment).Topic(string).QueryParam(Dictionary<string,object>)
ParameterTypeRequiredDescription
DeviceIdstringYesDevice ID
PushTypePNPushTypeYesAccepted values: PNPushType.GCM, PNPushType.FCM, PNPushType.APNS2.
EnvironmentPushEnvironmentAPNs2 onlyPNPushType.APNS2 only. Apple APNs server (refer to this Apple document) to contact. Valid values are Development and Production.
TopicstringAPNs2 onlyPNPushType.APNS2 only. Notification topic name (usually the application's bundle identifier).
QueryParamDictionary<string, object>OptionalDictionary object to pass name/value pairs as query string params with PubNub URL request for debug purpose.
AsyncPNCallbackDeprecatedPNCallback of type PNPushRemoveAllChannelsResult.
ExecutePNCallbackYesPNCallback of type PNPushRemoveAllChannelsResult.

Basic Usage

Remove all push notifications:

// for FCM/GCM
pubnub.RemoveAllPushNotificationsFromDeviceWithPushToken()
    .DeviceId("googleDevice")
    .PushType(PNPushType.GCM)
    .Execute(new PNPushRemoveAllChannelsResultExt((r, s) => {
        Console.WriteLine(pubnub.JsonPluggableLibrary.SerializeToJsonString(r));
    }));

// for APNS2
pubnub.RemoveAllPushNotificationsFromDeviceWithPushToken()
    .DeviceId("appleDevice")
    .PushType(PNPushType.APNS2)
    .Topic("myapptopic")
    .Environment(PushEnvironment.Development)
    .Execute(new PNPushRemoveAllChannelsResultExt((r, s) => {
        Console.WriteLine(pubnub.JsonPluggableLibrary.SerializeToJsonString(r));
    }));

Returns

The RemoveAllPushNotificationsFromDeviceWithPushToken() operation returns a PNPushRemoveAllChannelsResult which contains the following property:

Property NameTypeDescription
PNPushRemoveAllChannelsResultObjectReturns empty object.
PNStatusObjectReturns status of request if error occurred or not.
← Message PersistenceObjects →
  • Adding Device to Channel
    • Description
    • Method(s)
    • Basic Usage
    • Returns
  • Listing Channels For Device
    • Description
    • Method(s)
    • Basic Usage
    • Returns
  • Removing Device From Channel
    • Description
    • Method(s)
    • Basic Usage
    • Returns
  • Remove all push notifications
    • Description
    • Method(s)
    • Basic Usage
    • Returns
© PubNub Inc. - Privacy Policy