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:
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)?`
)
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
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:
func listAPNSPushChannelRegistrations(
for deviceToken: Data,
on topic: String,
environment: PushEnvironment = .development,
custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
completion: `((Result<[String], Error>) -> Void)?`
)
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
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:
func removeAPNSDevicesOnChannels(
_ removals: [String],
device token: Data,
on topic: String,
environment: PushEnvironment = .development,
custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
completion: `((Result<[String], Error>) -> Void)?`
)
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
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:
func removeAllAPNSPushDevice(
for deviceToken: Data,
on topic: String,
environment: PushEnvironment = .development,
custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
completion: ((Result<Void, Error>) -> Void)?
)
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
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:
func addPushChannelRegistrations(
_ additions: [String],
for deviceToken: Data,
of pushType: PubNub.PushService = .apns,
custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
completion: `((Result<[String], Error>) -> Void)?`
)
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
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:
func listPushChannelRegistrations(
for deviceToken: Data,
of pushType: PubNub.PushService = .apns,
custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
completion: `((Result<[String], Error>) -> Void)?`
)
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
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)?`
)
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
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)?
)
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