Skip to content
47 changes: 38 additions & 9 deletions src/pages/docs/platform/account/app/notifications.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,35 @@ Before you can start using Ably's [push notification](/docs/push) services, you
* Copy everything between and including `-----BEGIN CERTIFICATE-----` and `-----END CERTIFICATE-----`, and paste it into the **PEM cert** text box of the Apple push notification service section of your Ably notifications app [dashboard](https://ably.com/accounts).
* Similarly, copy everything between and including `-----BEGIN PRIVATE KEY-----` and `-----END PRIVATE KEY-----`, and paste it into the **PEM private key** text box of the same section. Then, click **Save**.

#### APNs sandbox endpoint <a id="apns-sandbox"/>

Apple provides both production and sandbox endpoints for APNs. The sandbox endpoint is used for testing push notifications during development, while the production endpoint is used for live apps.

When to use the sandbox endpoint:
- During app development and testing.
- For test/staging environments.
- When using development provisioning profiles.
- For internal testing before app store release.

When to use the production endpoint:
- For live apps distributed through the App Store.
- For production environments.
- When using distribution provisioning profiles.

Important considerations:
- Device tokens generated in the sandbox environment will **not work** in production, ensuring safe testing.
- Many developers maintain separate Ably apps: one configured for sandbox (testing) and another for production.
- Device tokens are environment-specific and cannot be used interchangeably.

How to configure the sandbox endpoint:
1. In the Ably [dashboard](https://ably.com/accounts), navigate to the **Notifications** tab under app settings.
2. Go to **push notifications setup** and click **configure push**.
3. In the **Apple push notification service** section, look for the **sandbox endpoint** option.
4. Enable the sandbox endpoint checkbox to use Apple's testing environment.
5. Click **save** to apply the changes.

This separation between sandbox and production environments ensures that test notifications don't reach real users and provides a safe environment for development and testing.

## Push inspector

The Push inspector tool enables you to manually send push notifications by specifying the required data and notification fields. This tool helps test and debug your notification setup before going live.
Expand All @@ -50,26 +79,26 @@ Define the content of your push notification using the fields below:

| Field | Purpose | How to Use |
| ----- | ------- | ---------- |
| **Notification title** | A title for the push notification, which will appear as the headline on the user's device. | Enter a short, clear title that captures the essence of the notification. |
| **Notification body** | The main content of the notification to be displayed below the title. | Write the key information or message that you want the user to read. |
| **Notification data** | Optional JSON data that the app can use for specific actions upon receiving the notification. | Include any extra data needed for app functionality, such as custom metadata or instructions. |
| Notification title | A title for the push notification, which will appear as the headline on the user's device. | Enter a short, clear title that captures the essence of the notification. |
| Notification body | The main content of the notification to be displayed below the title. | Write the key information or message that you want the user to read. |
| Notification data | Optional JSON data that the app can use for specific actions upon receiving the notification. | Include any extra data needed for app functionality, such as custom metadata or instructions. |

### Push notification target

Direct your push notifications to specific targets within the Ably platform. Select the appropriate target according to your notification strategy:

| Target | Purpose | How to Use |
| ------ | ------- | ---------- |
| **Channel name** | Push notifications to all subscribers of a specific channel. | Enter the channel name and click **push to channel** to notify all devices subscribed to that channel. |
| **Device ID** | Send a notification directly to a specific device. | Enter the Device ID and click **push to device** to target a single device with the notification. |
| **Client ID** | Notify a specific client registered with Ably. | Enter the Client ID and click **push to client** to send the notification to the chosen client. |
| Channel name | Push notifications to all subscribers of a specific channel. | Enter the channel name and click push to channel to notify all devices subscribed to that channel. |
| Device ID | Send a notification directly to a specific device. | Enter the Device ID and click push to device to target a single device with the notification. |
| Client ID | Notify a specific client registered with Ably. | Enter the Client ID and click push to client to send the notification to the chosen client. |

## Push inspector widget

The Push Inspector widget allows you to monitor and manage your push notification infrastructure directly from the Ably dashboard. It provides insights into channel subscriptions, device registrations, and client registrations, making it easier to debug and optimize your notification setup.

| Section | Purpose | How to Use |
| ------- | ------- | ---------- |
| **Channel subscriptions** | View and inspect all channels currently subscribed to push notifications. | Click **inspect channel** to see detailed information about a specific channel, including the number of subscribers and recent activity. |
| **Device registrations** | Access a list of all devices registered to receive push notifications. | Click **inspect device** to view detailed information about a specific device, such as its registration status, platform, and recent notifications. |
| **Client registrations** | Get an overview of all clients registered for push notifications within your Ably account. | Click **inspect client ID** to see detailed information about a specific client, including its subscriptions and recent activity. |
| Channel subscriptions | View and inspect all channels currently subscribed to push notifications. | Click inspect channel to see detailed information about a specific channel, including the number of subscribers and recent activity. |
| Device registrations | Access a list of all devices registered to receive push notifications. | Click inspect device to view detailed information about a specific device, such as its registration status, platform, and recent notifications. |
| Client registrations | Get an overview of all clients registered for push notifications within the Ably account. | Click inspect client ID to see detailed information about a specific client, including its subscriptions and recent activity. |
4 changes: 4 additions & 0 deletions src/pages/docs/platform/pricing/faqs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ FAQs related to pricing concepts and package limits.

The [limit](/docs/platform/pricing/limits#connection) on concurrent connections is for the maximum number of realtime clients [connected](/docs/connect) to Ably simultaneously at any point in time. HTTP requests such as those from REST clients do not count towards this number, as it is solely related to realtime connections.

Push notifications and connections: Devices registered for [push notifications](/docs/push) don't count toward concurrent connection limits when they're not actively connected to Ably, since push notifications are delivered through the device's operating system rather than maintaining an active connection.

### How do you count concurrent channels? <a id="concurrent-channels"/>

The [limit](/docs/platform/pricing/limits#channel) on concurrent channels is for the maximum number of channels that are active simultaneously at any point in time.
Expand All @@ -37,6 +39,8 @@ The [limit](/docs/platform/pricing/limits#channel) on concurrent channels is for

A channel will automatically close when there are no more realtime clients attached, and approximately one minute has passed since the last realtime client detached or since a message was published to the channel.

Push notifications and channels: When publishing [push notifications](/docs/push) via channels, those channels become activated and count toward concurrent (peak) channel count for billing purposes, even if no realtime clients are connected to them.

For example, if you have 10,000 users, and at your busiest time of the month there is a single spike where 500 customers establish a realtime connection to Ably and each attach to one unique channel, and one global shared channel. The concurrent number of channels would be the sum of the 500 unique channels per client and the one global shared channel, so 501 concurrent channels.

### How is maximum message size measured? <a id="message-size"/>
Expand Down
72 changes: 72 additions & 0 deletions src/pages/docs/push/configure/device.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,78 @@ private ClientOptions GetAblyOptions(string clientId)
```
</Code>

#### Manual device registration with cross-platform push services <a id="cross-platform"/>

In some scenarios, you may want to use FCM for iOS devices instead of APNs, or manually register devices with custom platform configurations. This is useful when using Firebase's unified messaging system across both Android and iOS platforms.

<Aside data-type='important'>
When using manual device registration, be aware that the local device will default to APNs for iOS. You must explicitly set the platform and transport type to override this behavior.
</Aside>

To manually register a device using FCM with iOS:

1. Use the Firebase iOS SDK to obtain an FCM registration token.
2. Create a `DeviceDetails` object with the appropriate platform and transport configuration.
3. Register the device using the Push Admin API.

<Code>
```swift
// Get FCM token from Firebase iOS SDK first
// Then create DeviceDetails object manually

let deviceDetails = ARTDeviceDetails(id: ULID().ulidString)
deviceDetails.secret = generateSecret()
deviceDetails.platform = "ios" // or "android"
deviceDetails.formFactor = "phone" // or "tablet", "tv", "watch", "desktop", "car"
deviceDetails.clientId = "clientA"
deviceDetails.metadata = NSMutableDictionary()
deviceDetails.push.recipient = [
"transportType": "fcm", // Use FCM instead of APNs
"registrationToken": "your-fcm-registration-token"
]

// Register the device using Push Admin API
rest.push.admin.deviceRegistrations.save(deviceDetails) { error in
if let error = error {
print("Registration failed: \(error)")
} else {
print("Device registered successfully")
}
}
```

```objc
// Get FCM token from Firebase iOS SDK first
// Then create DeviceDetails object manually

ARTDeviceDetails *deviceDetails = [[ARTDeviceDetails alloc] initWithId:[[NSUUID UUID] UUIDString]];
deviceDetails.secret = [self generateSecret];
deviceDetails.platform = @"ios"; // or @"android"
deviceDetails.formFactor = @"phone"; // or @"tablet", @"tv", @"watch", @"desktop", @"car"
deviceDetails.clientId = @"clientA";
deviceDetails.metadata = [[NSMutableDictionary alloc] init];
deviceDetails.push.recipient = @{
@"transportType": @"fcm", // Use FCM instead of APNs
@"registrationToken": @"your-fcm-registration-token"
};

// Register the device using Push Admin API
[rest.push.admin.deviceRegistrations save:deviceDetails callback:^(ARTErrorInfo *error) {
if (error) {
NSLog(@"Registration failed: %@", error);
} else {
NSLog(@"Device registered successfully");
}
}];
```
</Code>

This approach allows:
- Using FCM for both Android and iOS devices for unified push messaging.
- Overriding the default platform-specific push service assignments.
- Maintaining full control over device registration parameters.
- Integration with Firebase's analytics and other services across platforms.

#### Test your push notification activation <a id="test-push"/>

* Use the Ably [dashboard](https://ably.com/accounts) or [API](https://ably.com/docs/docs/api/realtime-sdk/push-admin) to send a test push notification to a registered device.
Expand Down
93 changes: 91 additions & 2 deletions src/pages/docs/push/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,19 @@ redirect_from:

Push notifications notify user devices or browsers regardless of whether an application is open and running. They deliver information, such as app updates, social media alerts, or promotional offers, directly to the user's screen. Ably sends push notifications to devices using [Firebase Cloud Messaging](https://firebase.google.com/docs/cloud-messaging) or [Apple Push Notification Service](https://developer.apple.com/notifications/), and to browsers using [Web Push](https://developer.mozilla.org/en-US/docs/Web/API/Push_API). Push notifications don't require a device or browser to stay connected to Ably. Instead, a device's or browser's operating system or web browser maintains its own battery-efficient transport to receive notifications.

## Billing and connection considerations <a id="billing"/>

Push notifications have specific billing implications that differ from regular realtime connections:

- Push subscriptions don't count as connections: Devices registered for push notifications don't count toward [concurrent connection](/docs/platform/pricing/limits#connection) limits when they're not actively connected to Ably.
- Channel activation affects billing: When publishing push notifications via channels, those channels become activated and count toward concurrent (peak) channel count for billing purposes.
- Multiple devices, one message count: Publishing a single push notification to multiple devices via a channel counts as one outbound message per recipient device.

You can publish push notifications to user devices or browsers [directly](/docs/push/publish/#direct-publishing) or [via channels](#via-channels).

**Publishing directly** sends push notifications to specific devices or browsers identified by unique identifiers, such as a `deviceId` or a `clientId`. This approach is akin to sending a personal message or alerts directly to an individual user's device or browser, bypassing the need for channel subscriptions. It excels in targeted and personalized communications, such as alerts specific to a user's actions, account notifications, or customized updates.
Publishing directly sends push notifications to specific devices or browsers identified by unique identifiers, such as a `deviceId` or a `clientId`. This approach is akin to sending a personal message or alerts directly to an individual user's device or browser, bypassing the need for channel subscriptions. It excels in targeted and personalized communications, such as alerts specific to a user's actions, account notifications, or customized updates.

**Publishing via channels** uses a [Pub/Sub](/docs/channels/messages) model. Messages are sent to channels to which multiple devices or browsers can subscribe. When a message is published to a channel, all devices or browsers subscribed to that channel receive the notification. This approach is particularly powerful for simultaneously publishing messages to multiple users.
Publishing via channels uses a [Pub/Sub](/docs/channels/messages) model. Messages are sent to channels to which multiple devices or browsers can subscribe. When a message is published to a channel, all devices or browsers subscribed to that channel receive the notification. This approach is particularly powerful for simultaneously publishing messages to multiple users.

## Push notification process

Expand Down Expand Up @@ -107,3 +115,84 @@ const channel = realtime.channels.get('[meta]log:push');
channel.subscribe(msg => console.log(msg));
```
</Code>

## Troubleshooting push notifications <a id="troubleshooting"/>

If not receiving expected push notifications, follow these debugging steps:

### Verify device registration

Check if the device is registered in the Ably dashboard:
1. Go to Notifications tab → Device inspector
2. Search for the device using `deviceId` or `clientId`
3. Verify device state:
- ACTIVE: Ready to receive notifications
- FAILED: Check error details (common: registration expired, invalid token)

### Test delivery

Use the [push inspector](/docs/platform/account/app/notifications#push-inspector) in the dashboard to send test notifications directly to the device.

### Check for errors

Monitor the `[meta]log:push` channel for delivery errors. Common platform-specific issues:

APNs (iOS):
- BadDeviceToken: Environment mismatch (sandbox vs production)
- DeviceTokenNotForTopic: Bundle ID mismatch in certificate

FCM (Android):
- FcmTransport not configured: Invalid service account JSON
- 403 Forbidden: FCM API not enabled or permission issues
- 404 NOT_FOUND: Device unregistered (app uninstalled)

Web Push:
- Service worker registration failed: Conflicting VAPID keys from previous registrations

### Cannot publish push notifications

If unable to publish push notifications on channels, check these common issues:

#### Channel rules

Push notifications are disabled by default on all channels. Explicitly enable push notifications for each channel or namespace:

1. Go to the Ably dashboard → App settings → Channel rules.
2. Create or edit a rule for your channel/namespace.
3. Enable "Push notifications enabled".

#### Permissions

Ensure the publisher has the correct capabilities:

- Publishing requires `publish` capability for the channel.
- Push-specific operations may require additional push capabilities.

#### Invalid payload

Verify the push payload in the message `extras` field is valid:

- Must include a `push` object with valid notification structure.
- Check payload format matches platform requirements (APNs, FCM, Web Push).

### Duplicate notifications

If receiving duplicate push notifications for the same device, this typically occurs when a device has both a `deviceId` and `clientId` subscription to the same channel:

- `deviceId` subscriptions deliver notifications to a single specific device.
- `clientId` subscriptions deliver notifications to all devices sharing that client ID.

If a device has both subscription types, it will receive the notification twice. To resolve:
1. Use the [push inspector widget](/docs/platform/account/app/notifications#push-inspector-widget) to check channel subscriptions.
2. Remove either the `deviceId` or `clientId` subscription for the affected device.

### Debug checklist

- Device shows as ACTIVE in dashboard.
- Push credentials configured correctly.
- Environment settings match (sandbox/production).
- App has notification permissions.
- No errors in `[meta]log:push` channel.
- Check for duplicate subscriptions (both `deviceId` and `clientId`).

For detailed troubleshooting steps, see the [push inspector documentation](/docs/platform/account/app/notifications#push-inspector) and [error logging](/docs/metadata-stats/metadata/subscribe#log).
Loading