Live Activities on iOS with the React Native SDK
When using the React Native SDK, Live Activities can be managed in two different ways:
- TypeScript API (React Native layer) – Allows you to retrieve active Live Activities, subscribe them to the backend, and listen for push updates directly from TypeScript.
- Native iOS integration – Gives you full access to Live Activities APIs, including push token generation and updates. See the Native iOS Live Activities Integration guide for detailed instructions.
Note: Push token generation (
PushToStart
andPushTokenUpdates
) cannot be triggered from React Native. This must be implemented in the native iOS layer, which then sends tokens to your backend for targeting Live Activities.
TypeScript API Reference
All methods return results asynchronously through callbacks. Let's do this example code and reference with the attribute name: TimerWidgetAttributes.
Get List of Active Live Activities
Retrieves all active Live Activities currently associated with the device.
import { LiveActivity } from 'indigitall-react-native-plugin';
LiveActivity.getListEnabledLiveActivities(
(liveActivities) => {
console.log("Active Live Activities:", liveActivities);
},
(error) => {
console.error("Error fetching live activities:", error);
}
);
Subscribe to Live Activities
Sends a list of Live Activities the device is subscribed to, so the backend can target them with push updates.
const activities = [
{ liveActivityExternalId: "order_123", iosAttributesType: "TimerWidgetAttributes" }
];
LiveActivity.subscribeToLiveActivities(
{ activities },
(result) => {
console.log("Successfully registered live activities:", result);
},
(error) => {
console.error("Error subscribing to live activities:", error);
}
);
Set PushToStart Token Updates
Native-only limitation: The actual token retrieval must be done in iOS native code, then passed to this method.
const tokenParams = {
token: "hexadecimal_push_to_start_token",
iosAttributesType: "TimerWidgetAttributes"
};
LiveActivity.setPushToStartTokenUpdates(
tokenParams,
(response) => {
console.log("PushToStart token sent successfully:", response);
},
(error) => {
console.error("Error sending PushToStart token:", error);
}
);
Set Push Token Updates
Updates the push token for an already running Live Activity.
const tokenUpdateParams = {
token: "hexadecimal_push_token",
liveActivityExternalId: "order_123"
};
LiveActivity.setPushTokenUpdates(
tokenUpdateParams,
(response) => {
console.log("Push token update sent successfully:", response);
},
(error) => {
console.error("Error updating push token:", error);
}
);
Push Reception Callback
Registers a callback to handle incoming push notifications, including Live Activity events.
import { NativeEventEmitter } from 'react-native';
import IndigitallReactNative from 'indigitall-react-native-plugin';
const eventEmitter = new NativeEventEmitter(IndigitallReactNative);
eventEmitter.addListener('onMessageReceived', async (event: any) => {
console.log("Push received:", event);
if (event.pushType === "LIVE_ACTIVITY") {
if (event.liveActivityEventType === "START") {
console.log("Live Activity started:", event);
} else if (event.liveActivityEventType === "UPDATE") {
console.log("Live Activity updated:", event);
} else if (event.liveActivityEventType === "END") {
console.log("Live Activity ended:", event);
}
}
});
Example: Full Live Activities Workflow in React Native (iOS)
import { NativeEventEmitter } from 'react-native';
import IndigitallReactNative, { LiveActivity } from 'indigitall-react-native-plugin';
// 1. Get current active Live Activities
LiveActivity.getListEnabledLiveActivities(
(liveActivities) => {
console.log("Active Live Activities:", liveActivities);
// 2. Subscribe them to the backend
LiveActivity.subscribeToLiveActivities(
{ activities: liveActivities },
(result) => {
console.log("Live activities subscribed successfully:", result);
},
(error) => {
console.error("Subscription error:", error);
}
);
},
(error) => {
console.error("Error fetching live activities:", error);
}
);
// 3. Set PushToStart token (token must come from native iOS code)
const pushToStartParams = {
token: "hexadecimal_push_to_start_token",
iosAttributesType: "TimerWidgetAttributes"
};
LiveActivity.setPushToStartTokenUpdates(
pushToStartParams,
(response) => {
console.log("PushToStart token sent:", response);
},
(error) => {
console.error("Error sending PushToStart token:", error);
}
);
// 4. Set Push token updates (token must come from native iOS code)
const pushTokenParams = {
token: "hexadecimal_push_token",
liveActivityExternalId: "order_123"
};
LiveActivity.setPushTokenUpdates(
pushTokenParams,
(response) => {
console.log("Push token update sent:", response);
},
(error) => {
console.error("Error updating push token:", error);
}
);
// 5. Listen for push events
const eventEmitter = new NativeEventEmitter(IndigitallReactNative);
eventEmitter.addListener('onMessageReceived', async (event: any) => {
console.log("Push received:", event);
if (event.pushType === "LIVE_ACTIVITY") {
if (event.liveActivityEventType === "START") {
console.log("Live Activity started:", event);
} else if (event.liveActivityEventType === "UPDATE") {
console.log("Live Activity updated:", event);
} else if (event.liveActivityEventType === "END") {
console.log("Live Activity ended:", event);
}
}
});