---
source_url: https://www.pubnub.com/docs/sdks/ruby/api-reference/mobile-push
title: Mobile Push Notifications API for Ruby SDK
updated_at: 2026-06-05T11:13:17.395Z
sdk_name: PubNub Ruby SDK
sdk_version: 6.0.2
---

> 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 Notifications API for Ruby SDK

PubNub Ruby SDK, use the latest version: 6.0.2

Install:

```bash
gem install pubnub@6.0.2
```

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)

Use the following method(s) in the Ruby SDK:

```ruby
pubnub.add_channels_to_push(
    push_token: push_token,
    push_gateway: push_gateway,
    channel: channel,
    topic: topic,
    environment: environment,
    auth_key: auth_key,
    http_sync: http_sync,
    callback: callback
)
```

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| push_token | String | Yes |  | Device token. |
| push_gateway | String | Yes |  | Backend to use. Accepted values: `gcm`, `apns2`. |
| channel | String | Yes |  | Comma-separated channels to add. |
| topic | String | Optional |  | APNs topic (bundle identifier). Required if `push_gateway` is `apns2`. |
| environment | String | Optional |  | APNs environment. Required if `push_gateway` is `apns2`. Default: `development`. Accepted values: `development`, `production`. |
| auth_key | String | Optional |  | Access Manager authorization key (if Access Manager is enabled). |
| http_sync | Boolean | Optional |  | If `false`, runs asynchronously and returns a `Future`. If `true`, returns an array of envelopes (even if one). Default: `false`. |
| callback | Lambda | Optional |  | Callback for each returned `envelope`. For async calls, use `Future#value` to get the result. |

### Sample code

#### Add device to channel

:::tip Reference code
This example is a self-contained code snippet ready to be run. It includes necessary imports and executes methods with console logging. Use it as a reference when working with other examples in this document.
:::

```ruby
require 'pubnub'

def add_device_to_channel(pubnub)
  # For FCM/GCM
  pubnub.add_channels_to_push(
    push_token: 'push_token',
    push_gateway: 'gcm',
    channel: 'channel1,channel2'
  ) do |envelope|
    if envelope.status[:error]
      puts "FCM/GCM Error: #{envelope.status[:error]}"
    else
      puts "FCM/GCM Success: Device added to channels."
    end
  end

  # For APNS2 token has to be 32 or 100 characters hexadecimal string
  pubnub.add_channels_to_push(
    push_token: '00000000000000000000000000000000',
    push_gateway: 'apns2',
    channel: 'channel1,channel2',
    topic: 'myapptopic',
    environment: 'development'
  ) do |envelope|
    if envelope.status[:error]
      puts "APNS2 Error: #{envelope.status[:error]}"
    else
      puts "APNS2 Success: Device added to channels."
    end
  end
end

def main
  # Configuration for PubNub instance
  pubnub = Pubnub.new(
    subscribe_key: ENV.fetch('SUBSCRIBE_KEY', 'demo'),
    user_id: 'myUniqueUserId'
  )

  # Add device to channel
  add_device_to_channel(pubnub)
  sleep 2 # Allow time for the async operation to complete
end

if __FILE__ == $0
  main
end
```

### Response

```ruby
#<Pubnub::Envelope
    @result = {
        :code => 200,
        :operation => :add_channels_to_push,
        :data => [1, "Modified Channels"]
    },
    @status = {
        :code => 200,
        :category => :ack,
        :error => false,
    }
>
```

## 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-).
:::

List channels that have push notifications enabled for the specified device token.

### Method(s)

Use the following method(s) in the Ruby SDK:

```ruby
pubnub.list_push_provisions(
    push_token: push_token,
    push_gateway: push_gateway,
    topic: topic,
    environment: environment,
    auth_key: auth_key,
    http_sync: http_sync,
    callback: callback
)
```

| Parameter | Description |
| --- | --- |
| `push_token` *Type: String | Device token. |
| `push_gateway` *Type: String | Backend to use. Accepted values: `gcm`, `apns2`. |
| `topic`Type: String | APNs topic (bundle identifier). Required if `push_gateway` is `apns2`. |
| `environment`Type: String | APNs environment. Required if `push_gateway` is `apns2`. Default: `development`. Accepted values: `development`, `production`. |
| `auth_key`Type: String | Access Manager authorization key (if Access Manager is enabled). |
| `http_sync`Type: Boolean | If `false`, runs asynchronously and returns a `Future`. If `true`, returns an array of envelopes. Default: `false`. |
| `callback`Type: Lambda accepting one parameter | Callback for each returned `envelope`. For async calls, use `Future#value`. |

### Sample code

#### List channels for device

```ruby
# for FCM/GCM
pubnub.list_push_provisions(
    push_token: 'push_token',
    type: 'gcm'
) do |envelope|
    puts envelope
end

# for APNS2
pubnub.list_push_provisions(
    push_token: 'push_token',
    type: 'apns2',
    topic: 'myapptopic'
    environment: 'development'
) do |envelope|
    puts envelope
end
```

### Response

```ruby
#<Pubnub::Envelope
    @result = {
        :code => 200,
        :operation => :list_push_provisions,
        :data => ["channel1", "channel2"]
    },
    @status = {
        :code => 200,
        :category => :ack,
        :error => false,
    }
>
```

## 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 mobile push notifications on a set of channels.

### Method(s)

Use the following method(s) in the Ruby SDK:

```ruby
pubnub.remove_channels_from_push(push_token: push_token, push_gateway: push_gateway, channel: channel, topic: topic, environment: environment, auth_key: auth_key, http_sync: http_sync, callback: callback)
```

| Parameter | Description |
| --- | --- |
| `push_token` *Type: String | Device token. |
| `push_gateway` *Type: String | Backend to use. Accepted values: `gcm`, `apns2`. |
| `channel` *Type: String | Comma-separated channels to remove. |
| `topic`Type: String | APNs topic (bundle identifier). Required if `push_gateway` is `apns2`. |
| `environment`Type: String | APNs environment. Required if `push_gateway` is `apns2`. Default: `development`. Accepted values: `development`, `production`. |
| `auth_key`Type: String | Access Manager authorization key (if Access Manager is enabled). |
| `http_sync`Type: Boolean | If `false`, runs asynchronously and returns a `Future`. If `true`, returns an array of envelopes. Default: `false`. |
| `callback`Type: Lambda accepting one parameter | Callback for each returned `envelope`. For async calls, use `Future#value`. |

### Sample code

#### Remove device from channel

```ruby
# for FCM/GCM
pubnub.remove_channels_from_push(
    push_token: 'push_token',
    remove: 'channel1,channel2',
    type: 'gcm'
) do |envelope|
    puts envelope
end

# for APNS2
pubnub.remove_channels_from_push(
    push_token: 'push_token',
    remove: 'channel1,channel2',
    type: 'apns2',
    topic: 'myapptopic',
    environment: 'development'
) do |envelope|
    puts envelope
end
```

### Response

```ruby
#<Pubnub::Envelope
    @result = {
        :code => 200,
        :operation => :remove_channels_from_push,
        :data => [1, "Modified Channels"]
    },
    @status = {
        :code => 200,
        :category => :ack,
        :error => false,
    }
>
```

## Remove a device from all 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 mobile push notifications from all channels registered with the specified device token.

### Method(s)

Use the following method(s) in the Ruby SDK:

```ruby
pubnub.remove_device_from_push(
    push_token: push_token,
    push_gateway: push_gateway,
    topic: topic,
    environment: environment,
    auth_key: auth_key,
    http_sync: http_sync,
    callback: callback
)
```

| Parameter | Description |
| --- | --- |
| `push_token` *Type: String | Device token. |
| `push_gateway` *Type: String | Backend to use. Accepted values: `gcm`, `apns2`. |
| `topic`Type: String | APNs topic (bundle identifier). Required if `push_gateway` is `apns2`. |
| `environment`Type: String | APNs environment. Required if `push_gateway` is `apns2`. Default: `development`. Accepted values: `development`, `production`. |
| `auth_key`Type: String | Access Manager authorization key (if Access Manager is enabled). |
| `http_sync`Type: Boolean | If `false`, runs asynchronously and returns a `Future`. If `true`, returns an array of envelopes. Default: `false`. |
| `callback`Type: Lambda accepting one parameter | Callback for each returned `envelope`. For async calls, use `Future#value`. |

### Sample code

#### Remove all mobile push notifications

```ruby
# for FCM/GCM
pubnub.remove_device_from_push(
    push_token: 'push_token',
    type: 'gcm'
) do |envelope|
    puts envelope
end

# for APNS2
pubnub.remove_device_from_push(
    push_token: 'push_token',
    type: 'apns2',
    topic: 'myapptopic'
    environment: 'development'
) do |envelope|
    puts envelope
end
```

### Response

```ruby
#<Pubnub::Envelope
    @result = {
        :code => 200,
        :operation => :remove_device_from_push,
        :data => [1, "Modified Channels"]
    },
    @status = {
        :code => 200,
        :category => :ack,
        :error => false,
    }
>
```

## Terms in this document

* **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.