Mobile Push Notifications API for PubNub Cocoa Swift SDK
This SDK has been replaced by a new PubNub Swift SDK written purely in Swift. Check it out here
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.
Adding Device to 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.
Description
Enable mobile push notifications on provided set of channels.
Method(s)
To run Adding Device to Channel
you can use the following method(s) in the Swift SDK:
open func addPushNotificationsOnChannels(_ channels: [String], withDevicePushToken pushToken: Data, andCompletion closure: PubNub.PNPushNotificationsStateModificationCompletionBlock? = nil)
Parameter | Type | Required | Description |
---|---|---|---|
channels | [String] | Yes | List of channel names for which mobile push notifications should be enabled . |
pushToken | Data | Yes | Device push token which should be used to enable mobile push notifications on specified set of channels . |
closure | PNPushNotificationsStateModificationCompletionBlock | No | Add mobile push notifications process completion closure which has one argument - request processing status to report about whether data push was successful or not (errorData contains error information in case of failure). |
Basic Usage
Adding Device to Channel
self.client.addPushNotificationsOnChannels(["wwdc", "google.io"],
withDevicePushToken: self.devicePushToken,
andCompletion: { (status) in
if !status.isError {
// Handle successful push notification enabling on passed channels.
}
else {
/**
Handle modification error. Check 'category' property
to find out possible reason because of which request did fail.
Review 'errorData' property (which has PNErrorData data type) of status
object to get additional information about issue.
show all 20 linesResponse
Response objects which is returned by client when APNS Add Device API is used:
open class PNAcknowledgmentStatus : PNErrorStatus {
}
Adding Device to Channel (Builder Pattern)
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.
Description
Enable mobile push notifications on provided set of channels.
Method(s)
To run Adding Device to Channel
you can use the following method(s) in the Swift SDK.
APNS Token
push().enable().channels([String]).apnsToken(Data).environment(PNAPNSProduction).topic(String)performWithCompletion(PNPushNotificationsStateModificationCompletionBlock)
Parameter | Type | Required | Description |
---|---|---|---|
channels | [String] | Yes | List of channel names for which mobile push notifications should be enabled . |
apnsToken | Data | Yes | APNS-provided device push token which should be used to enable push notifications on specified set of channels . |
topic | String | Yes | Notifications topic name (usually it is application's bundle identifier). |
environment | PNAPNSEnvironment | Yes | One of PNAPNSEnvironment fields which specify environment within which device should manage list of channels with enabled notifications (works only APNs2). |
closure | PNPushNotificationsStateModificationCompletionBlock | No | Push notifications addition on channels processing completion closure which pass only one argument - request processing status to report about how data pushing was successful or not. |
Optional arguments
This method uses the builder pattern, you can remove the arguments which are optional.
FCM Token
push().enable().channels([String]).fcmToken(String).performWithCompletion(PNPushNotificationsStateModificationCompletionBlock)
Parameter | Type | Required | Description |
---|---|---|---|
channels | [String] | Yes | List of channel names for which mobile push notifications should be enabled . |
fcmToken | String | Yes | FCM-provided device push token which should be used to enable push notifications on specified set of channels . |
closure | PNPushNotificationsStateModificationCompletionBlock | No | Push notifications addition on channels processing completion closure which pass only one argument - request processing status to report about how data pushing was successful or not. |
Optional arguments
This method uses the builder pattern, you can remove the arguments which are optional.
Basic Usage
APNS2 Token
self.client.push().enable().channels(["channel1", "channel2"])
.apnsToken(self.pushToken)
.environment(PNAPNSProduction)
.topic("myapptopic")
.performWithCompletion({ (status) in
if !status.isError {
// Handle successful push notification enabling on passed channels.
} else {
/**
Handle modification error. Check 'category' property
to find out possible reason because of which request did fail.
Review 'errorData' property (which has PNErrorData data type) of status
object to get additional information about issue.
Request can be resent using: status.retry()
show all 18 linesFCM Token
self.client.push().enable().channels(["channel1", "channel2"])
.fcmToken(self.pushToken)
.performWithCompletion({ (status) in
if !status.isError {
// Handle successful push notification enabling on passed channels.
} else {
/**
Handle modification error. Check 'category' property
to find out possible reason because of which request did fail.
Review 'errorData' property (which has PNErrorData data type) of status
object to get additional information about issue.
Request can be resent using: status.retry()
*/
}
show all 16 linesResponse
Response objects which is returned by client when APNS Add Device API is used:
open class PNAcknowledgmentStatus : PNErrorStatus {
}
Listing 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.
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 Swift SDK:
open func pushNotificationEnabledChannelsForDeviceWithPushToken(_ pushToken: Data, andCompletion closure: PubNub.PNPushNotificationsStateAuditCompletionBlock)
Parameter | Type | Required | Description |
---|---|---|---|
pushToken | Data | Yes | Device push token. |
closure | PNPushNotificationsStateAuditCompletionBlock | Yes | The completion closure which will be called when the processing is complete, has two arguments: result - in case of successful processing (data will contain results of mobile push notifications audit operation); status - in case of error while processing (errorData contains error information). |
Basic Usage
Listing Channels For Device
self.client.pushNotificationEnabledChannelsForDeviceWithPushToken(self.devicePushToken,
andCompletion: { (result, status) in
if status == nil {
// Handle downloaded list of channels using: result.data.channels
}
else {
/**
Handle audition error. Check 'category' property
to find out possible reason because of which request did fail.
Review 'errorData' property (which has PNErrorData data type) of status
object to get additional information about issue.
show all 19 linesResponse
Response objects which is returned by client when APNS List Devices API is used:
open class PNAPNSEnabledChannelsData : PNServiceData {
// Channels with active mobile push notifications.
open var channels: [String] { get }
}
open class PNAPNSEnabledChannelsResult : PNResult {
// Stores reference on APNS enabled channels audit request processing information.
open var data: PNAPNSEnabledChannelsData { get }
}
Listing Channels For Device (Builder Pattern)
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.
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 Swift SDK.
APNS Token
push().audit().apnsToken(Data).environment(PNAPNSEnvironment).topic(String).performWithCompletion(PNPushNotificationsStateModificationCompletionBlock)
Parameter | Type | Required | Description |
---|---|---|---|
apnsToken | Data | Yes | APNS-provided device push token against which search on PubNub service should be performed. |
topic | String | Yes | Notifications topic name (usually it is application's bundle identifier). |
environment | PNAPNSEnvironment | Yes | One of PNAPNSEnvironment fields which specify environment within which device should manage list of channels with enabled notifications (works only APNs2). |
closure | PNPushNotificationsStateAuditCompletionBlock | Yes | Push notifications status processing completion closure which pass two arguments: result - in case of successful request processing data field will contain results of push notifications audit operation; status - in case if error occurred during request processing. |
Optional arguments
This method uses the builder pattern, you can remove the arguments which are optional.
FCM Token
push().audit().fcmToken(String).performWithCompletion(PNPushNotificationsStateModificationCompletionBlock)
Parameter | Type | Required | Description |
---|---|---|---|
fcmToken | String | Yes | FCM-provided device push token against which search on PubNub service should be performed. |
closure | PNPushNotificationsStateAuditCompletionBlock | Yes | Push notifications status processing completion closure which pass two arguments: result - in case of successful request processing data field will contain results of push notifications audit operation; status - in case if error occurred during request processing. |
Optional arguments
This method uses the builder pattern, you can remove the arguments which are optional.
Basic Usage
APNS2 Token
self.client.push().audit().apnsToken(self.pushToken)
.environment(PNAPNSProduction)
.topic("myapptopic")
.performWithCompletion({ (result, status) in
if status == nil {
// Handle downloaded list of channels using: result.data.channels
} else {
/**
Handle audition error. Check 'category' property
to find out possible reason because of which request did fail.
Review 'errorData' property (which has PNErrorData data type) of status
object to get additional information about issue.
Request can be resent using: status.retry();
*/
show all 17 linesFCM Token
self.client.push().audit().fcmToken(self.pushToken)
.performWithCompletion({ (result, status) in
if status == nil {
// Handle downloaded list of channels using: result.data.channels
} else {
/**
Handle audition error. Check 'category' property
to find out possible reason because of which request did fail.
Review 'errorData' property (which has PNErrorData data type) of status
object to get additional information about issue.
Request can be resent using: status.retry();
*/
}
}];
Response
Response objects which is returned by client when APNS List Devices API is used:
open class PNAPNSEnabledChannelsData : PNServiceData {
// Channels with active mobile push notifications.
open var channels: [String] { get }
}
open class PNAPNSEnabledChannelsResult : PNResult {
// Stores reference on APNS enabled channels audit request processing information.
open var data: PNAPNSEnabledChannelsData { get }
}
Removing Device From 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.
Description
Disable mobile push notifications on provided set of channels.
Method(s)
To run Removing Device From Channel
you can use the following method(s) in the Swift SDK:
open func removePushNotificationsFromChannels(_ channels: [String], withDevicePushToken pushToken: Data, andCompletion closure: PubNub.PNPushNotificationsStateModificationCompletionBlock? = nil)
Parameter | Type | Required | Description |
---|---|---|---|
channels | [String] | Yes | List of channel names for which mobile push notifications should be disabled.If passed list is empty all notifications will be disabled. |
pushToken | Data | Yes | Device push token which should be used to disable push notifications on specified set of channels . |
closure | PNChannelGroupChangeCompletionBlock | No | The completion closure which will be called when the processing is complete, has one argument: request processing status - in case of error while processing (errorData contains error information). |
Basic Usage
Removing Device From Channel
self.client.removePushNotificationsFromChannels(["wwdc","google.io"],
withDevicePushToken: self.devicePushToken,
andCompletion: { (status) in
if !status.isError {
// Handle successful push notification disabling on passed channels.
}
else {
/**
Handle modification error. Check 'category' property
to find out possible reason because of which request did fail.
Review 'errorData' property (which has PNErrorData data type) of status
object to get additional information about issue.
show all 20 linesResponse
Response objects which is returned by client when APNS Remove Device API is used:
open class PNAcknowledgmentStatus : PNErrorStatus {
}
Removing Device From Channel (Builder Pattern)
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.
Description
Disable mobile push notifications on provided set of channels.
Method(s)
To run Removing Device From Channel
you can use the following method(s) in the Swift SDK
APNS2 Token
push().disable().channels([String]).apnsToken(Data).environment(PNAPNSEnvironment).topic(String).performWithCompletion(PNPushNotificationsStateModificationCompletionBlock)
Parameter | Type | Required | Description |
---|---|---|---|
channels | [String] | Yes | List of channel names for which mobile push notifications should be disabled. If passed list is empty all notifications will be disabled . |
apnsToken | Data | Yes | APNS-provided device push token which should be used to disable push notifications on specified set of channels . |
topic | String | Yes | Notifications topic name (usually it is application's bundle identifier). |
environment | PNAPNSEnvironment | Yes | One of PNAPNSEnvironment fields which specify environment within which device should manage list of channels with enabled notifications (works only APNs2). |
closure | PNPushNotificationsStateModificationCompletionBlock | No | Push notifications removal from channels processing completion closure which pass only one argument - request processing status to report about how data pushing was successful or not. |
Optional arguments
This method uses the builder pattern, you can remove the arguments which are optional.
FCM Token
push().disable().channels([String]).fcmToken(String).performWithCompletion(PNPushNotificationsStateModificationCompletionBlock)
Parameter | Type | Required | Description |
---|---|---|---|
channels | [String] | Yes | List of channel names for which push notifications should be disabled. If passed list is empty all notifications will be disabled . |
fcmToken | String | Yes | FCM-provided device push token which should be used to disable push notifications on specified set of channels . |
closure | PNPushNotificationsStateModificationCompletionBlock | No | Push notifications removal from channels processing completion closure which pass only one argument - request processing status to report about how data pushing was successful or not. |
Optional arguments
This method uses the builder pattern, you can remove the arguments which are optional.
Basic Usage
APNS Token
self.client.push().disable().channels(["channel1", "channel2"])
.apnsToken(self.pushToken)
.environment(PNAPNSProduction)
.topic("myapptopic")
.performWithCompletion({ (status) in
if !status.isError {
// Handle successful push notification disabling on passed channels.
} else {
/**
Handle modification error. Check 'category' property
to find out possible reason because of which request did fail.
Review 'errorData' property (which has PNErrorData data type) of status
object to get additional information about issue.
Request can be resent using: status.retry();
show all 18 linesFCM Token
self.client.push().disable().channels(["channel1", "channel2"])
.fcmToken(self.pushToken)
.performWithCompletion({ (status) in
if !status.isError {
// Handle successful push notification disabling on passed channels.
} else {
/**
Handle modification error. Check 'category' property
to find out possible reason because of which request did fail.
Review 'errorData' property (which has PNErrorData data type) of status
object to get additional information about issue.
Request can be resent using: status.retry();
*/
}
show all 16 linesResponse
Response objects which is returned by client when APNS Remove Device API is used:
open class PNAcknowledgmentStatus : PNErrorStatus {
}
Remove all 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.
Description
Disable mobile push notifications from all channels registered with the specified pushToken.
Method(s)
To run Remove all mobile push notifications
, you can use the following method(s) in the Swift SDK:
open func removeAllPushNotificationsFromDeviceWithPushToken(_ pushToken: Data, andCompletion closure: PubNub.PNPushNotificationsStateModificationCompletionBlock? = nil)
Parameter | Type | Required | Description |
---|---|---|---|
pushToken | Data | Yes | Device push token which should be used to disable all mobile push notifications registered with it. |
closure | PNPushNotificationsStateModificationCompletionBlock | No | The completion closure which will be called when the processing is complete, has one argument: request processing status - in case of error while processing (errorData contains error information). |
Basic Usage
Remove all mobile push notifications
self.client.removeAllPushNotificationsFromDeviceWithPushToken(self.devicePushToken,
andCompletion: { (status) in
if !status.isError {
/**
Handle successful push notification disabling for all channels associated with
specified device push token.
*/
}
else {
/**
Handle modification error. Check 'category' property
to find out possible reason because of which request did fail.
show all 22 linesResponse
Response objects which is returned by client when APNS Remove All Devices API is used:
open class PNAcknowledgmentStatus : PNErrorStatus {
}
Remove all mobile push notifications (Builder Pattern)
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.
Description
Disable mobile push notifications from all channels registered with the specified pushToken.
Method(s)
To run Remove all mobile push notifications
, you can use the following method(s) in the Swift SDK:
APNS2 Token
push().disable().channels([String]).apnsToken(Data).environment(PNAPNSEnvironment).topic(String).performWithCompletion(PNPushNotificationsStateModificationCompletionBlock)
Parameter | Type | Required | Description |
---|---|---|---|
channels | [String] | Yes | List of channel names for which mobile push notifications should be disabled. If passed list is empty all notifications will be disabled . |
apnsToken | Data | Yes | APNS-provided device push token which should be used to disable push notifications on specified set of channels . |
topic | String | Yes | Notifications topic name (usually it is application's bundle identifier). |
environment | PNAPNSEnvironment | Yes | One of PNAPNSEnvironment fields which specify environment within which device should manage list of channels with enabled notifications (works only APNs2). |
closure | PNPushNotificationsStateModificationCompletionBlock | No | Push notifications removal from channels processing completion closure which pass only one argument - request processing status to report about how data pushing was successful or not. |
Optional arguments
This method uses the builder pattern, you can remove the arguments which are optional.
FCM Token
push().disable().channels([String]).fcmToken(String).performWithCompletion(PNPushNotificationsStateModificationCompletionBlock)
Parameter | Type | Required | Description |
---|---|---|---|
channels | [String] | Yes | List of channel names for which push notifications should be disabled. If passed list is empty all notifications will be disabled . |
fcmToken | String | Yes | FCM-provided device push token which should be used to disable push notifications on specified set of channels . |
closure | PNPushNotificationsStateModificationCompletionBlock | No | Push notifications removal from channels processing completion closure which pass only one argument - request processing status to report about how data pushing was successful or not. |
Optional arguments
This method uses the builder pattern, you can remove the arguments which are optional.
Basic Usage
APNS2 Token
self.client.push().disable().channels(["channel1", "channel2"])
.apnsToken(self.pushToken)
.environment(PNAPNSProduction)
.topic("myapptopic")
.performWithCompletion({ (status) in
if !status.isError {
// Handle successful push notification disabling on passed channels.
} else {
/**
Handle modification error. Check 'category' property
to find out possible reason because of which request did fail.
Review 'errorData' property (which has PNErrorData data type) of status
object to get additional information about issue.
Request can be resent using: status.retry();
show all 18 linesFCM Token
self.client.push().disable().channels(["channel1", "channel2"])
.fcmToken(self.pushToken)
.performWithCompletion({ (status) in
if !status.isError {
// Handle successful push notification disabling on passed channels.
} else {
/**
Handle modification error. Check 'category' property
to find out possible reason because of which request did fail.
Review 'errorData' property (which has PNErrorData data type) of status
object to get additional information about issue.
Request can be resent using: status.retry();
*/
}
show all 16 linesResponse
open class PNAcknowledgmentStatus : PNErrorStatus {
}