Mobile Push Notifications API for Swift Native 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.
Add a device to APNs2 channels
note
Enable Mobile Push Notifications for your key in the Admin Portal. See how to enable add-on features.
Enable APNs2 mobile push notifications on a set of channels.
Method(s)
Use the following method(s) in the Swift SDK:
1func addAPNSDevicesOnChannels(
2 _ additions: [String],
3 device token: Data,
4 on topic: String,
5 environment: PubNub.PushEnvironment = .development,
6 custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
7 completion: `((Result<[String], Error>) -> Void)?`
8)
Parameter | Description |
---|---|
_ *Type: Data Default: n/a | Channels to add for the device. |
device *Type: Data Default: n/a | Device token. |
on *Type: String Default: n/a | APNs topic (bundle identifier). |
environment *Type: PubNub.PushEnvironment Default: .development | APNs environment. |
custom Type: PubNub.RequestConfiguration Default: PubNub.RequestConfiguration() | Per-request configuration. |
completion Type: ((Result<[String], Error>) -> Void)? Default: nil | Async result callback. |
Completion handler result
Success
An Array
of channels added for notifications on a specific device token.
Failure
An Error
describing the failure.
Sample code
Reference code
Adding device to channel
1
List APNs2 channels for a device
note
Enable Mobile Push Notifications for your key in the Admin Portal. See how to enable add-on features.
List channels with APNs2 push notifications for the specified device token and topic.
Method(s)
Use the following method(s) in the Swift SDK:
1func listAPNSPushChannelRegistrations(
2 for deviceToken: Data,
3 on topic: String,
4 environment: PushEnvironment = .development,
5 custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
6 completion: `((Result<[String], Error>) -> Void)?`
7)
Parameter | Description |
---|---|
for *Type: Data Default: n/a | Device token. |
on *Type: String Default: n/a | APNs topic (bundle identifier). |
environment *Type: PubNub.PushEnvironment Default: .development | APNs environment. |
custom Default: PubNub.RequestConfiguration() | Per-request configuration. |
completion Type: ((Result<[String], Error>) -> Void)? Default: nil | Async result callback. |
Completion handler result
Success
An Array
of channels added for notifications on a specific device token.
Failure
An Error
describing the failure.
Sample code
List APNs2 channels for device
1
Remove a device from APNs2 channels
note
Enable Mobile Push Notifications for your key in the Admin Portal. See how to enable add-on features.
Disable APNs2 mobile push notifications on a set of channels.
Method(s)
Use the following method(s) in the Swift SDK:
1func removeAPNSDevicesOnChannels(
2 _ removals: [String],
3 device token: Data,
4 on topic: String,
5 environment: PushEnvironment = .development,
6 custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
7 completion: `((Result<[String], Error>) -> Void)?`
8)
Parameter | Description |
---|---|
_ *Type: Data Default: n/a | Channels to remove for the device. |
device *Type: Data Default: n/a | Device token. |
on *Type: String Default: n/a | APNs topic (bundle identifier). |
environment *Type: PubNub.PushEnvironment Default: .development | APNs environment. |
custom Default: PubNub.RequestConfiguration() | Per-request configuration. |
completion Type: ((Result<[String], Error>) -> Void)? Default: nil | Async result callback. |
Completion handler result
Success
An Array
of channels disabled from notifications on a specific device token.
Failure
An Error
describing the failure.
Sample code
Remove device from channel
1
Remove a device from all APNs2 channels
note
Enable Mobile Push Notifications for your key in the Admin Portal. See how to enable add-on features.
Disable APNs2 mobile push notifications from all channels registered for the specified device token.
Method(s)
Use the following method(s) in the Swift SDK:
1func removeAllAPNSPushDevice(
2 for deviceToken: Data,
3 on topic: String,
4 environment: PushEnvironment = .development,
5 custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
6 completion: ((Result<Void, Error>) -> Void)?
7)
Parameter | Description |
---|---|
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 Void
indicating a success.
Failure
An Error
describing the failure.
Sample code
Remove all mobile push notifications
1
Add device to channel (deprecated)
note
Enable Mobile Push Notifications for your key in the Admin Portal. See how to enable add-on features.
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)
Use the following method(s) in the Swift SDK:
1func addPushChannelRegistrations(
2 _ additions: [String],
3 for deviceToken: Data,
4 of pushType: PubNub.PushService = .apns,
5 custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
6 completion: `((Result<[String], Error>) -> Void)?`
7)
Parameter | Description |
---|---|
_ *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.
Sample code
Add device to channel
1
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)
Use the following method(s) in the Swift SDK:
1func listPushChannelRegistrations(
2 for deviceToken: Data,
3 of pushType: PubNub.PushService = .apns,
4 custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
5 completion: `((Result<[String], Error>) -> Void)?`
6)
Parameter | Description |
---|---|
for *Type: Data Default: n/a | Device token. |
of *Type: PubNub.PushService Default: .apns | Remote Notification service type. |
custom Default: PubNub.RequestConfiguration() | Per-request configuration. |
completion Type: ((Result<[String], Error>) -> Void)? Default: nil | Async result callback. |
Completion handler result
Success
An Array
of channels added for notifications on a specific device token.
Failure
An Error
describing the failure.
Sample code
Listing channels for device
1
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:
1removePushChannelRegistrations(
2 _ removals: [String],
3 for deviceToken: Data,
4 of pushType: PubNub.PushService = .apns,
5 custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
6 completion: `((Result<[String], Error>) -> Void)?`
7)
Parameter | Description |
---|---|
_ *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.
Sample code
Remove device from channel
1
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:
1func removeAllPushChannelRegistrations(
2 for deviceToken: Data,
3 of pushType: PubNub.PushService = .apns,
4 custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
5 completion: ((Result<Void, Error>) -> Void)?
6)
Parameter | Description |
---|---|
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.
Sample code
Remove all mobile push notifications
1