Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/pages/docs/platform/account/app/notifications.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,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. |
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
4 changes: 2 additions & 2 deletions src/pages/docs/push/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ Push notifications notify user devices or browsers regardless of whether an appl

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
118 changes: 118 additions & 0 deletions src/pages/docs/push/publish.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1345,3 +1345,121 @@ channel = rest.channels.get('pushenabled:foo');
channel.publish(message);
```
</Code>

## Handling push notifications on devices <a id="handling-push-notifications"/>

After Ably delivers push notifications to devices, mobile applications need to handle them appropriately. This includes processing the notification content, navigating users to relevant sections of the app, and implementing deep linking functionality.

### Deep links and app navigation <a id="deep-links"/>

Deep links allow push notifications to navigate users directly to specific screens or content within mobile applications. While Ably handles the delivery of push notifications, creating and handling deep links is implemented within mobile app code.

Deep links are not created using Ably itself. Instead, handle deep links in app push notification receivers and use the notification data to determine where to navigate users.

#### Android deep linking with push notifications

On Android, implement deep links and app navigation in several ways.

Using `onMessageReceived` (recommended):

Handle push notifications in `FirebaseMessagingService` and create deep links programmatically:

```java
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// Extract data from Ably push notification
Map<String, String> data = remoteMessage.getData();

// Create deep link based on notification data
if (data.containsKey("screen")) {
String targetScreen = data.get("screen");
Intent intent = createDeepLinkIntent(targetScreen, data);
startActivity(intent);
}
}

private Intent createDeepLinkIntent(String screen, Map<String, String> data) {
Intent intent = new Intent(this, MainActivity.class);
intent.putExtra("navigate_to", screen);
intent.putExtra("data", new Bundle(data));
return intent;
}
```

Using `click_action` with intent filters:

Specify a `click_action` in the push notification payload and handle it with intent filters:

1. Add `click_action` to the notification payload when publishing via Ably:

```json
{
"push": {
"notification": {
"title": "New Message",
"body": "You have a new message",
"click_action": "OPEN_CHAT_SCREEN"
},
"data": {
"chat_id": "12345",
"user_id": "67890"
}
}
}
```

2. Configure intent filters in `AndroidManifest.xml`:
```xml
<activity android:name=".ChatActivity">
<intent-filter>
<action android:name="OPEN_CHAT_SCREEN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
```

#### iOS deep linking with push notifications

On iOS, handle deep links in the app delegate or scene delegate:

Using URL schemes:
```swift
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
// Extract navigation data from Ably push notification
if let screen = userInfo["screen"] as? String {
navigateToScreen(screen, with: userInfo)
}
}

private func navigateToScreen(_ screen: String, with data: [AnyHashable: Any]) {
// Implement navigation logic based on screen parameter
switch screen {
case "chat":
if let chatId = data["chat_id"] as? String {
showChatScreen(chatId: chatId)
}
case "profile":
if let userId = data["user_id"] as? String {
showProfileScreen(userId: userId)
}
default:
showMainScreen()
}
}
```

Using Universal Links:
Configure universal links in the app and handle them when users tap on push notifications:

```swift
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
guard userActivity.activityType == NSUserActivityTypeBrowsingWeb,
let url = userActivity.webpageURL else {
return false
}

// Handle universal link from push notification
handleUniversalLink(url)
return true
}
```