---
source_url: https://www.pubnub.com/docs/sdks/cocoa-swift/api-reference/mobile-push
title: Mobile Push API for Cocoa Swift SDK
updated_at: 2026-05-27T17:02:10.012Z
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# Mobile Push API for Cocoa Swift SDK

This SDK has been replaced by a new PubNub Swift SDK written purely in Swift. Check it out [here](https://www.pubnub.com/docs/sdks/swift)

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](https://www.pubnub.com/docs/general/push/send).

## Add a device to a push notifications channel

:::note Requires Mobile Push Notifications add-on
Enable Mobile Push Notifications for your key in the [Admin Portal](https://admin.pubnub.com/). See how to [enable add-on features](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-).
:::

Enable mobile push notifications on a set of channels.

### Method(s)

To run `Adding Device to Channel` you can use the following method(s) in the Swift SDK:

```swift
open func addPushNotificationsOnChannels(
    _ channels: [String],
    withDevicePushToken pushToken: Data,
    andCompletion closure: PubNub.PNPushNotificationsStateModificationCompletionBlock? = nil
)
```

| Parameter | Type | Required | Default | 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 | Optional |  | 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). |

### Sample code

#### Add device to channel

```swift
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

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

```swift
open class PNAcknowledgmentStatus : PNErrorStatus {

}
```

## Add a device to a push notifications channel (builder pattern)

:::note Requires Mobile Push Notifications add-on
Enable Mobile Push Notifications for your key in the [Admin Portal](https://admin.pubnub.com/). See how to [enable add-on features](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-).
:::

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

```swift
push().enable()
    .channels([String])
    .apnsToken(Data)
    .environment(PNAPNSProduction)
    .topic(String)
    .performWithCompletion(PNPushNotificationsStateModificationCompletionBlock)
```

| Parameter | Description |
| --- | --- |
| `channels` *Type: [String] | List of `channel` names for which mobile push notifications should be `enabled`. |
| `apnsToken` *Type: Data | APNS-provided device push token which should be used to enable push `notifications` on specified set of `channels`. |
| `topic` *Type: String | Notifications topic name (usually it is application's bundle identifier). |
| `environment` *Type: PNAPNSEnvironment | One of `PNAPNSEnvironment` fields which specify environment within which device should manage list of channels with enabled notifications (works only APNs2). |
| `closure`Type: PNPushNotificationsStateModificationCompletionBlock | 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. |

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

#### FCM token

```swift
push().enable()
    .channels([String])
    .fcmToken(String)
    .performWithCompletion(PNPushNotificationsStateModificationCompletionBlock)
```

| Parameter | Description |
| --- | --- |
| `channels` *Type: [String] | List of `channel` names for which mobile push notifications should be `enabled`. |
| `fcmToken` *Type: String | FCM-provided device push token which should be used to enable push `notifications` on specified set of `channels`. |
| `closure`Type: PNPushNotificationsStateModificationCompletionBlock | 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. |

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

### Sample code

#### APNS2 token

```swift
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()
            */
        }
    });
```

#### FCM token

```swift
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

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

```swift
open class PNAcknowledgmentStatus : PNErrorStatus {

}
```

## List push notifications channels for a device

:::note Requires Mobile Push Notifications add-on
Enable Mobile Push Notifications for your key in the [Admin Portal](https://admin.pubnub.com/). See how to [enable add-on features](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-).
:::

Get all channels with push notifications for the specified push token.

### Method(s)

To run `Listing Channels For Device` you can use the following method(s) in the Swift SDK:

```swift
open func pushNotificationEnabledChannelsForDeviceWithPushToken(
    _ pushToken: Data,
    andCompletion closure: PubNub.PNPushNotificationsStateAuditCompletionBlock
)
```

| Parameter | Description |
| --- | --- |
| `pushToken` *Type: Data | Device push token. |
| `closure` *Type: PNPushNotificationsStateAuditCompletionBlock | 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). |

### Sample code

#### List channels for device

```swift
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

Response objects which is returned by client when APNS List Devices API is used:

```swift
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 }
}
```

## List push notifications channels for a device (builder pattern)

:::note Requires Mobile Push Notifications add-on
Enable Mobile Push Notifications for your key in the [Admin Portal](https://admin.pubnub.com/). See how to [enable add-on features](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-).
:::

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

```swift
push().audit()
    .apnsToken(Data)
    .environment(PNAPNSEnvironment)
    .topic(String)
    .performWithCompletion(PNPushNotificationsStateModificationCompletionBlock)
```

| Parameter | Description |
| --- | --- |
| `apnsToken` *Type: Data | APNS-provided device `push token` against which search on PubNub service should be performed. |
| `topic` *Type: String | Notifications topic name (usually it is application's bundle identifier). |
| `environment` *Type: PNAPNSEnvironment | One of `PNAPNSEnvironment` fields which specify environment within which device should manage list of channels with enabled notifications (works only APNs2). |
| `closure` *Type: PNPushNotificationsStateAuditCompletionBlock | 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. |

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

#### FCM token

```swift
push().audit()
    .fcmToken(String)
    .performWithCompletion(PNPushNotificationsStateModificationCompletionBlock)
```

| Parameter | Description |
| --- | --- |
| `fcmToken` *Type: String | FCM-provided device push token against which search on PubNub service should be performed. |
| `closure` *Type: PNPushNotificationsStateAuditCompletionBlock | 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. |

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

### Sample code

#### APNS2 token

```swift
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();
            */
        }
    }];
```

#### FCM token

```swift
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:

```swift
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 }
}
```

## Remove a device from push notifications channels

:::note Requires Mobile Push Notifications add-on
Enable Mobile Push Notifications for your key in the [Admin Portal](https://admin.pubnub.com/). See how to [enable add-on features](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-).
:::

Disable push notifications on selected channels.

### Method(s)

To run `Removing Device From Channel` you can use the following method(s) in the Swift SDK:

```swift
open func removePushNotificationsFromChannels(
    _ channels: [String],
    withDevicePushToken pushToken: Data,
    andCompletion closure: PubNub.PNPushNotificationsStateModificationCompletionBlock? = nil
)
```

| Parameter | Description |
| --- | --- |
| `channels` *Type: [String] | List of channel names for which mobile push notifications should be disabled.`If passed list is empty all notifications will be disabled.` |
| `pushToken` *Type: Data | Device push token which should be used to disable push `notifications` on specified set of `channels`. |
| `closure`Type: PNChannelGroupChangeCompletionBlock | 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). |

### Sample code

#### Remove device from channel

```swift
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

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

```swift
open class PNAcknowledgmentStatus : PNErrorStatus {

}
```

## Remove a device from push notifications channels (builder pattern)

:::note Requires Mobile Push Notifications add-on
Enable Mobile Push Notifications for your key in the [Admin Portal](https://admin.pubnub.com/). See how to [enable add-on features](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-).
:::

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

```swift
push().disable()
    .channels([String])
    .apnsToken(Data)
    .environment(PNAPNSEnvironment)
    .topic(String)
    .performWithCompletion(PNPushNotificationsStateModificationCompletionBlock)
```

| Parameter | Description |
| --- | --- |
| `channels` *Type: [String] | List of channel names for which mobile push notifications should be disabled. `If passed list is empty all notifications will be disabled`. |
| `apnsToken` *Type: Data | APNS-provided device push token which should be used to disable push `notifications` on specified set of `channels`. |
| `topic` *Type: String | Notifications topic name (usually it is application's bundle identifier). |
| `environment` *Type: PNAPNSEnvironment | One of `PNAPNSEnvironment` fields which specify environment within which device should manage list of channels with enabled notifications (works only APNs2). |
| `closure`Type: PNPushNotificationsStateModificationCompletionBlock | 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. |

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

#### FCM token

```swift
push().disable()
    .channels([String])
    .fcmToken(String)
    .performWithCompletion(PNPushNotificationsStateModificationCompletionBlock)
```

| Parameter | Description |
| --- | --- |
| `channels` *Type: [String] | List of channel names for which push `notifications` should be disabled. `If passed list is empty all notifications will be disabled`. |
| `fcmToken` *Type: String | FCM-provided device push token which should be used to disable push `notifications` on specified set of `channels`. |
| `closure`Type: PNPushNotificationsStateModificationCompletionBlock | 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. |

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

### Sample code

#### APNS token

```swift
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();
            */
        }
    });
```

#### FCM token

```swift
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

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

```swift
open class PNAcknowledgmentStatus : PNErrorStatus {

}
```

## Remove all mobile push notifications

:::note Requires Mobile Push Notifications add-on
Enable Mobile Push Notifications for your key in the [Admin Portal](https://admin.pubnub.com/). See how to [enable add-on features](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-).
:::

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:

```swift
open func removeAllPushNotificationsFromDeviceWithPushToken(
    _ pushToken: Data,
    andCompletion closure: PubNub.PNPushNotificationsStateModificationCompletionBlock? = nil
)
```

| Parameter | Description |
| --- | --- |
| `pushToken` *Type: Data | Device push token which should be used to disable all mobile push notifications registered with it. |
| `closure`Type: PNPushNotificationsStateModificationCompletionBlock | 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). |

### Sample code

#### Remove all mobile push notifications

```swift
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

Response objects which is returned by client when APNS Remove All Devices API is used:

```swift
open class PNAcknowledgmentStatus : PNErrorStatus {

}
```

## Remove all mobile push notifications (builder pattern)

:::note Requires Mobile Push Notifications add-on
Enable Mobile Push Notifications for your key in the [Admin Portal](https://admin.pubnub.com/). See how to [enable add-on features](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-).
:::

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

```swift
push().disable()
    .channels([String])
    .apnsToken(Data)
    .environment(PNAPNSEnvironment)
    .topic(String)
    .performWithCompletion(PNPushNotificationsStateModificationCompletionBlock)
```

| Parameter | Description |
| --- | --- |
| `channels` *Type: [String] | List of channel names for which mobile push notifications should be disabled. `If passed list is empty all notifications will be disabled`. |
| `apnsToken` *Type: Data | APNS-provided device push token which should be used to disable push `notifications` on specified set of `channels`. |
| `topic` *Type: String | Notifications topic name (usually it is application's bundle identifier). |
| `environment` *Type: PNAPNSEnvironment | One of `PNAPNSEnvironment` fields which specify environment within which device should manage list of channels with enabled notifications (works only APNs2). |
| `closure`Type: PNPushNotificationsStateModificationCompletionBlock | 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. |

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

#### FCM token

```swift
push().disable()
    .channels([String])
    .fcmToken(String)
    .performWithCompletion(PNPushNotificationsStateModificationCompletionBlock)
```

| Parameter | Description |
| --- | --- |
| `channels` *Type: [String] | List of channel names for which push `notifications` should be disabled. `If passed list is empty all notifications will be disabled`. |
| `fcmToken` *Type: String | FCM-provided device push token which should be used to disable push `notifications` on specified set of `channels`. |
| `closure`Type: PNPushNotificationsStateModificationCompletionBlock | 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. |

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

### Sample code

#### APNS2 token

```swift
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();
            */
        }
    });
```

#### FCM token

```swift
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

```swift
open class PNAcknowledgmentStatus : PNErrorStatus {

} 
```

## Terms in this document

* **Channel** - A pathway for sending and receiving messages between devices, created automatically when you first use it, that can handle any number of users and messages for different communication needs, like 1-1 text chats, group conversations, and other data streaming.
* **PubNub** - PubNub is a real-time messaging platform that provides APIs and SDKs for building scalable applications. It handles the complex infrastructure of real-time communication, including: Message delivery and persistence, Presence detection, Access control, Push notifications, File sharing, Serverless processing with Functions and Events & Actions, Analytics and monitoring with BizOps Workspace, AI-powered insights with Illuminate.
* **Push token** - A device identifier issued by a push provider (APNs or FCM) used to register a device for receiving mobile push notifications.
