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
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 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)
Completion handler result
Success
An Array of channels added for notifications on a specific device token.
Failure
An Error describing the failure.
Sample code
Adding device to channel
1
List APNs2 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.
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)
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
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 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)
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
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 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)
forrequired#- The device token used during registration.
onrequired#- The topic of the remote notification (which is typically the bundle ID for your app).
environmentrequired#- The APS environment to register the device.
custom#- An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the Request Configuration section.
completion#- The async
Resultof the method call.
Completion handler result
Success
A Voidindicating a success.
Failure
An Error describing the failure.
Sample code
Remove all mobile push notifications
1
Add device to channel (deprecated)
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 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)
_required#- The list of channels to add the device registration to.
forrequired#- A device token to identify the device for registration changes.
ofrequired#- The type of Remote Notification service used to send the notifications.
custom#- An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the Request Configuration section.
completion#- The async
Resultof 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. See Enable the features your app calls.
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)
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. See Enable the features your app calls.
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)
_required#- The list of channels to remove the device registration from.
forrequired#- A device token to identify the device for registration changes.
ofrequired#- The type of Remote Notification service used to send the notifications.
custom#- An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the Request Configuration section.
completion#- The async
Resultof 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. See Enable the features your app calls.
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)
forrequired#- A device token to identify the device for registration changes.
ofrequired#- The type of Remote Notification service used to send the notifications.
custom#- An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the Request Configuration section.
completion#- The async
Resultof 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