Skip to content
English

Notifications

The Notifications panel sends a push notification to your app on an iOS Simulator or Android emulator. On Android, it can also deliver it through your app’s notification handling when the FCM broadcast can’t reach the app.

Using Notifications in the desktop app

Accepts false | NotificationsPluginConfig Opt-in
NotificationsPluginConfig
OptionTypeDefaultDescription
expoNotificationsExpoNotificationsLike—The expo-notifications module. The desktop app's Send to device shows a notification through its handler when FCM can't reach the device.
onRemoteMessage(message: RemoteMessageLike) => unknown—Your handler for FCM messages, such as the function you pass to messaging().onMessage. It wins over expoNotifications when both are set.

Pass the handler that shows notifications in your app:

Pass the expo-notifications module. The notification is shown with scheduleNotificationAsync, using the payload’s notification title and body. A payload with only data uses data.title and data.message. The image isn’t shown.

import { init } from '@xerlock/client';
import * as Notifications from 'expo-notifications';
init({
notifications: { expoNotifications: Notifications },
});

If you pass both, onRemoteMessage is used.

ExpoNotificationsLike
MemberDescription
scheduleNotificationAsync(request: { content: { title?: string; body?: string; data?: Record<string, unknown>; sound?: boolean | string; }; trigger: null | { channelId: string }; }): Promise<string>Shows a notification through the app's notification handler. trigger: null shows it immediately.
RemoteMessageLike
MemberDescription
messageId: stringAlways starts with xerlock- for a message sent from the desktop app.
from: stringThe sender id. Always xerlock for a message sent from the desktop app.
sentTime: numberWhen the message was sent, in milliseconds since the epoch.
ttl: numberSeconds the message may live.
notification?: { title?: string; body?: string; android?: { channelId?: string; imageUrl?: string }; }The notification part, if the payload had one.
data?: Record<string, string>The custom data, with string values.

Leave out notifications, or pass false. Sending to an iOS Simulator, and over adb on Android, still works without it.

  • “Add notifications to the Xerlock client config to deliver through the app instead.”: the FCM broadcast failed and no handler is set. Pass expoNotifications or onRemoteMessage.
  • “The app has no handler for incoming notifications.”: pass expoNotifications or onRemoteMessage.
  • “The app’s notification handler threw an error.”: the toast shows the error your handler threw.