CocoaCocoaiOSSwiftCocoa Swift Mobile Push API Reference for Realtime Apps

Go to Storage & Playback


Requires Mobile Push Notifications add-on XRequires that the Mobile Push Notifications add-on is enabled for your key. See this page on enabling add-on features on your keys:

http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.
Enable push notifications on provided set of channels.
To run Adding Device to Channel you can use the following method(s) in the Swift SDK
  1. ParameterTypeRequiredDescription
    channels[String]YesList of channel names for which push notifications should be enabled.
    pushTokenDataYesDevice push token which should be used to enable push notifications on specified set of channels.
    closurePNPushNotificationsStateModificationCompletionBlockNoAdd 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).
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.

		 Request can be resent using: status.retry()
		 */
	}
})

Response objects which is returned by client when APNS Add Device API is used:

open class PNAcknowledgmentStatus : PNErrorStatus {

}
Requires Mobile Push Notifications add-on XRequires that the Mobile Push Notifications add-on is enabled for your key. See this page on enabling add-on features on your keys:

http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.
Enable push notifications on provided set of channels.
To run Adding Device to Channel you can use the following method(s) in the Swift SDK

  1. ParameterTypeRequiredDescription
    channels[String]YesList of channel names for which push notifications should be enabled.
    apnsTokenDataYesAPNS-provided device push token which should be used to enabled push notifications on specified set of channels.
    closurePNPushNotificationsStateModificationCompletionBlockNoPush 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.
     

    This method uses the builder pattern, you can remove the arguments which are optional.

  1. ParameterTypeRequiredDescription
    channels[String]YesList of channel names for which push notifications should be enabled.
    fcmTokenStringYesFCM-provided device push token which should be used to enabled push notifications on specified set of channels.
    closurePNPushNotificationsStateModificationCompletionBlockNoPush 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.
     

    This method uses the builder pattern, you can remove the arguments which are optional.


self.client.push().enable().channels(["channel1", "channel2"])
    .apnsToken(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()
            */
        }
    });
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()
            */
        }
    });

Response objects which is returned by client when APNS Add Device API is used:

open class PNAcknowledgmentStatus : PNErrorStatus {

}
Requires Mobile Push Notifications add-on XRequires that the Mobile Push Notifications add-on is enabled for your key. See this page on enabling add-on features on your keys:

http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.
Request for all channels on which push notification has been enabled using specified pushToken.
To run Listing Channels For Device you can use the following method(s) in the Swift SDK
  1. ParameterTypeRequiredDescription
    pushTokenDataYesDevice push token.
    closurePNPushNotificationsStateAuditCompletionBlockYesThe 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 push notifications audit operation); status - in case of error while processing (errorDatacontains error information).
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.

		 Request can be resent using: status.retry()
		 */
	}
})
Response objects which is returned by client when APNS List Devices API is used:
open class PNAPNSEnabledChannelsData : PNServiceData {
    
    // Channels with active 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 }
}
Requires Mobile Push Notifications add-on XRequires that the Mobile Push Notifications add-on is enabled for your key. See this page on enabling add-on features on your keys:

http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.
Request for all channels on which push notification has been enabled using specified pushToken.
To run Listing Channels For Device you can use the following method(s) in the Swift SDK

  1. ParameterTypeRequiredDescription
    apnsTokenDataYesAPNS-provided device push token against which search on PubNub service should be performed.
    closurePNPushNotificationsStateAuditCompletionBlockYesPush 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.
     

    This method uses the builder pattern, you can remove the arguments which are optional.

  1. ParameterTypeRequiredDescription
    fcmTokenStringYesFCM-provided device push token against which search on PubNub service should be performed.
    closurePNPushNotificationsStateAuditCompletionBlockYesPush 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.
     

    This method uses the builder pattern, you can remove the arguments which are optional.


self.client.push().audit().apnsToken(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();
            */
        }
    }];
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 objects which is returned by client when APNS List Devices API is used:
open class PNAPNSEnabledChannelsData : PNServiceData {
    
    // Channels with active 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 }
}
Requires Mobile Push Notifications add-on XRequires that the Mobile Push Notifications add-on is enabled for your key. See this page on enabling add-on features on your keys:

http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.
Disable push notifications on provided set of channels.
To run Removing Device From Channel you can use the following method(s) in the Swift SDK
  1. ParameterTypeRequiredDescription
    channels
    [String]
    Yes
    List of channel names for which 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 (errorDatacontains error information).
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.

		 Request can be resent using: status.retry();
		 */
	}
})
Response objects which is returned by client when APNS Remove Device API is used:
open class PNAcknowledgmentStatus : PNErrorStatus {

}
Requires Mobile Push Notifications add-on XRequires that the Mobile Push Notifications add-on is enabled for your key. See this page on enabling add-on features on your keys:

http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.
Disable push notifications on provided set of channels.
To run Removing Device From Channel you can use the following method(s) in the Swift SDK

  1. ParameterTypeRequiredDescription
    channels[String]YesList of channel names for which push notifications should be disabled. If passed list is empty all notifications will be disabled.
    apnsTokenDataYesAPNS-provided device push token which should be used to disable push notifications on specified set of channels.
    closurePNPushNotificationsStateModificationCompletionBlockNoPush 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.
     

    This method uses the builder pattern, you can remove the arguments which are optional.

  1. ParameterTypeRequiredDescription
    channels[String]YesList of channel names for which push notifications should be disabled. If passed list is empty all notifications will be disabled.
    fcmTokenStringYesFCM-provided device push token which should be used to disable push notifications on specified set of channels.
    closurePNPushNotificationsStateModificationCompletionBlockNoPush 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.
     

    This method uses the builder pattern, you can remove the arguments which are optional.


self.client.push().disable().channels(["channel1", "channel2"])
    .apnsToken(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();
            */
        }
    });
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();
            */
        }
    });
Response objects which is returned by client when APNS Remove Device API is used:
open class PNAcknowledgmentStatus : PNErrorStatus {

}
Requires Mobile Push Notifications add-on XRequires that the Mobile Push Notifications add-on is enabled for your key. See this page on enabling add-on features on your keys:

http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.
Disable push notifications from all channels which is registered with specified pushToken.
To run Remove all push notifications you can use the following method(s) in the Swift SDK
  1. ParameterTypeRequiredDescription
    pushToken
    Data
    Yes
    Device push token which should be used to disable all 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 (errorDatacontains error information).
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.
		 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 objects which is returned by client when APNS Remove All Devices API is used:
open class PNAcknowledgmentStatus : PNErrorStatus {

}

Go to Objects (BETA)