Mobile Push Notifications API for Swift Native 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.

Add Device to APNs2 Channels

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 APNs2 mobile push notifications on provided set of channels.

Method(s)

To run Adding Device to APNs2 Channel you can use the following method(s) in the Swift SDK:

func addAPNSDevicesOnChannels(
_ additions: [String],
device token: Data,
on topic: String,
environment: PubNub.PushEnvironment = .development,
custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
completion: `((Result<[String], Error>) -> Void)?`
)
* required
ParameterDescription
_ *
Type: Data
Default:
n/a
The list of channels to add the device registration to.
device *
Type: Data
Default:
n/a
The device to add/remove from the channels.
on *
Type: String
Default:
n/a
The topic of the remote notification (which is typically the bundle ID for your app).
environment *
Type: PubNub.PushEnvironment
Default:
.development
The APS environment to register the device.
custom
Type: PubNub.RequestConfiguration
Default:
PubNub.RequestConfiguration()
An object that allows for per-request customization of PubNub Configuration or Network Session.
completion
Type: ((Result<[String], Error>) -> Void)?
Default:
nil
The async Result of the method call.

Completion Handler Result

Success

An Array of channels added for notifications on a specific device token.

Failure

An Error describing the failure.

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.

Adding Device to Channel


List APNs2 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 APNs2 push notification has been enabled using specified device token and topic.

Method(s)

To run Listing APNs2 Channels For Device you can use the following method(s) in the Swift SDK:

func listAPNSPushChannelRegistrations(
for deviceToken: Data,
on topic: String,
environment: PushEnvironment = .development,
custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
completion: `((Result<[String], Error>) -> Void)?`
)
* required
ParameterDescription
for *
Type: Data
Default:
n/a
The device token used during registration.
on *
Type: String
Default:
n/a
The topic of the remote notification (which is typically the bundle ID for your app).
environment *
Type: PubNub.PushEnvironment
Default:
.development
The APS environment to register the device.
custom
Default:
PubNub.RequestConfiguration()
An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the Request Configuration section.
completion
Type: ((Result<[String], Error>) -> Void)?
Default:
nil
The async Result of the method call.

Completion Handler Result

Success

An Array of channels added for notifications on a specific device token.

Failure

An Error describing the failure.

Basic Usage

List APNs2 Channels For Device


Remove Device From APNs2 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 APNs2 Channel you can use the following method(s) in the Swift SDK:

func removeAPNSDevicesOnChannels(
_ removals: [String],
device token: Data,
on topic: String,
environment: PushEnvironment = .development,
custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
completion: `((Result<[String], Error>) -> Void)?`
)
* required
ParameterDescription
_ *
Type: Data
Default:
n/a
The list of channels to disable registration.
device *
Type: Data
Default:
n/a
The device to add/remove from the channels.
on *
Type: String
Default:
n/a
The topic of the remote notification (which is typically the bundle ID for your app).
environment *
Type: PubNub.PushEnvironment
Default:
.development
The APS environment to register the device.
custom
Default:
PubNub.RequestConfiguration()
An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the Request Configuration section.
completion
Type: ((Result<[String], Error>) -> Void)?
Default:
nil
The async Result of the method call.

Completion Handler Result

Success

An Array of channels disabled from notifications on a specific device token.

Failure

An Error describing the failure.

Basic Usage

Remove Device From Channel


Remove all APNs2 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 APNs2 mobile push notifications from all channels which is registered with specified pushToken.

Method(s)

To run Remove all APNs2 mobile push notifications you can use the following method(s) in the Swift SDK:

func removeAllAPNSPushDevice(
for deviceToken: Data,
on topic: String,
environment: PushEnvironment = .development,
custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
completion: ((Result<Void, Error>) -> Void)?
)
* required
ParameterDescription
for *
Type: Data
Default:
n/a
The device token used during registration.
on *
Type: String
Default:
n/a
The topic of the remote notification (which is typically the bundle ID for your app).
environment *
Type: PubNub.PushEnvironment
Default:
.development
The APS environment to register the device.
custom
Default:
PubNub.RequestConfiguration()
An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the Request Configuration section.
completion
Type: ((Result<[String], Error>) -> Void)?
Default:
nil
The async Result of the method call.

Completion Handler Result

Success

A Voidindicating a success.

Failure

An Error describing the failure.

Basic Usage

Remove all mobile push notifications


Add Device to Channel (deprecated)

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. This method is deprecated in favor of the corresponding HTTP/2-based APNs method above. Use only for legacy binary APNs interface publishing.

Method(s)

To run Adding Device to Channel you can use the following method(s) in the Swift SDK:

func addPushChannelRegistrations(
_ additions: [String],
for deviceToken: Data,
of pushType: PubNub.PushService = .apns,
custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
completion: `((Result<[String], Error>) -> Void)?`
)
* required
ParameterDescription
_ *
Type: [String]
Default:
n/a
The list of channels to add the device registration to.
for *
Type: Data
Default:
n/a
A device token to identify the device for registration changes.
of *
Type: PubNub.PushService
Default:
.apns
The type of Remote Notification service used to send the notifications.
custom
Default:
PubNub.RequestConfiguration()
An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the Request Configuration section.
completion
Type: ((Result<[String], Error>) -> Void)?
Default:
nil
The async Result of the method call.
Completion Handler Result
Success

An Array of channels added for notifications on a specific device token.

Failure

An Error describing the failure.

Basic Usage

Add Device to Channel

List Channels For Device (deprecated)

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. This method is deprecated in favor of the corresponding HTTP/2-based APNs method above. Use only for legacy binary APNs interface publishing.

Method(s)

To run Listing Channels For Device you can use the following method(s) in the Swift SDK:

func listPushChannelRegistrations(
for deviceToken: Data,
of pushType: PubNub.PushService = .apns,
custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
completion: `((Result<[String], Error>) -> Void)?`
)
* required
ParameterDescription
for *
Type: Data
Default:
n/a
A device token to identify the device for registration changes.
of *
Type: PubNub.PushService
Default:
.apns
The type of Remote Notification service used to send the notifications.
custom
Default:
PubNub.RequestConfiguration()
An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the Request Configuration section.
completion
Type: ((Result<[String], Error>) -> Void)?
Default:
nil
The async Result of the method call.
Completion Handler Result
Success

An Array of channels added for notifications on a specific device token.

Failure

An Error describing the failure.

Basic Usage

Listing Channels For Device

Remove Device From Channel (deprecated)

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. This method is deprecated in favor of the corresponding HTTP/2-based APNs method above. Use only for legacy binary APNs interface publishing.

Method(s)

To run Removing Device From Channel you can use the following method(s) in the Swift SDK:

removePushChannelRegistrations(
_ removals: [String],
for deviceToken: Data,
of pushType: PubNub.PushService = .apns,
custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
completion: `((Result<[String], Error>) -> Void)?`
)
* required
ParameterDescription
_ *
Type: [String]
Default:
n/a
The list of channels to remove the device registration from.
for *
Type: Data
Default:
n/a
A device token to identify the device for registration changes.
of *
Type: PubNub.PushService
Default:
.apns
The type of Remote Notification service used to send the notifications.
custom
Default:
PubNub.RequestConfiguration()
An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the Request Configuration section.
completion
Type: ((Result<[String], Error>) -> Void)?
Default:
nil
The async Result of the method call.
Completion Handler Result
Success

An Array of channels added for notifications on a specific device token.

Failure

An Error describing the failure.

Basic Usage

Remove Device From Channel

Remove all mobile push notifications (deprecated)

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. This method is deprecated in favor of the corresponding HTTP/2-based APNs method above. Use only for legacy binary APNs interface publishing.

Method(s)

To run Remove all mobile push notifications, you can use the following method(s) in the Swift SDK:

func removeAllPushChannelRegistrations(
for deviceToken: Data,
of pushType: PubNub.PushService = .apns,
custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
completion: ((Result<Void, Error>) -> Void)?
)
* required
ParameterDescription
for *
Type: Data
Default:
n/a
A device token to identify the device for registration changes.
of *
Type: PubNub.PushService
Default:
.apns
The type of Remote Notification service used to send the notifications.
custom
Default:
PubNub.RequestConfiguration()
An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the Request Configuration section.
completion
Type: ((Result<Void, Error>) -> Void)?
Default:
nil
The async Result of the method call.
Completion Handler Result
Success

A Void indicating a success.

Failure

An Error describing the failure.

Basic Usage

Remove all mobile push notifications

Last updated on