CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-react-native-onesignal

React Native SDK for OneSignal's push notification, email, SMS, and in-app messaging service

Pending
Overview
Eval results
Files

live-activities.mddocs/

Live Activities (iOS)

iOS-specific Live Activity support for dynamic, real-time widget updates including push-to-start and push-to-update functionality.

Note: All Live Activities functionality is iOS-only and will have no effect on Android devices.

Capabilities

Live Activity Management

Manage individual Live Activity sessions with enter and exit functionality.

/**
 * Indicate this device has entered a live activity, identified within OneSignal by the activityId.
 * Only applies to iOS.
 * @param activityId - The activity identifier the live activity on this device will receive updates for
 * @param token - The activity's update token to receive the updates
 * @param handler - Optional callback function
 */
function enter(activityId: string, token: string, handler?: Function): void;

/**
 * Indicate this device has exited a live activity, identified within OneSignal by the activityId.
 * Only applies to iOS.
 * @param activityId - The activity identifier the live activity on this device will no longer receive updates for
 * @param handler - Optional callback function
 */
function exit(activityId: string, handler?: Function): void;

Usage Examples:

import { OneSignal } from "react-native-onesignal";
import { Platform } from "react-native";

if (Platform.OS === 'ios') {
  // Start tracking a live activity (e.g., sports game, delivery)
  OneSignal.LiveActivities.enter(
    "game-12345", 
    "activity-update-token",
    (result) => {
      console.log('Live activity entered:', result);
    }
  );
  
  // Stop tracking when activity is complete
  OneSignal.LiveActivities.exit("game-12345", (result) => {
    console.log('Live activity exited:', result);
  });
}

Push-to-Start Token Management

Manage push-to-start tokens for Live Activities that can be remotely initiated.

/**
 * Indicate this device is capable of receiving pushToStart live activities for the activityType. 
 * The activityType must be the name of the struct conforming to ActivityAttributes that will be used 
 * to start the live activity. Only applies to iOS.
 * @param activityType - The name of the specific ActivityAttributes structure tied to the live activity
 * @param token - The activity type's pushToStart token
 */
function setPushToStartToken(activityType: string, token: string): void;

/**
 * Indicate this device is no longer capable of receiving pushToStart live activities for the activityType.
 * The activityType must be the name of the struct conforming to ActivityAttributes that will be used 
 * to start the live activity. Only applies to iOS.
 * @param activityType - The name of the specific ActivityAttributes structure tied to the live activity
 */
function removePushToStartToken(activityType: string): void;

Usage Examples:

if (Platform.OS === 'ios') {
  // Register for push-to-start delivery tracking
  OneSignal.LiveActivities.setPushToStartToken(
    "DeliveryTrackingAttributes", 
    "push-to-start-token"
  );
  
  // Unregister when no longer needed
  OneSignal.LiveActivities.removePushToStartToken("DeliveryTrackingAttributes");
}

Default Live Activity Setup

Use OneSignal's default Live Activity implementation for simplified setup.

/**
 * Enable the OneSignalSDK to setup the default DefaultLiveActivityAttributes structure,
 * which conforms to the OneSignalLiveActivityAttributes. When using this function, the
 * widget attributes are owned by the OneSignal SDK, which will allow the SDK to handle the
 * entire lifecycle of the live activity. Only applies to iOS.
 * @param options - Optional structure to provide for more granular setup options
 */
function setupDefault(options?: LiveActivitySetupOptions): void;

/**
 * Start a new LiveActivity that is modelled by the default DefaultLiveActivityAttributes
 * structure. The DefaultLiveActivityAttributes is initialized with the dynamic attributes
 * and content passed in. Only applies to iOS.
 * @param activityId - The activity identifier the live activity on this device will be started and eligible to receive updates for
 * @param attributes - A dynamic type containing the static attributes passed into DefaultLiveActivityAttributes  
 * @param content - A dynamic type containing the content attributes passed into DefaultLiveActivityAttributes
 */
function startDefault(activityId: string, attributes: object, content: object): void;

Usage Examples:

if (Platform.OS === 'ios') {
  // Setup default live activity with push-to-start and push-to-update
  OneSignal.LiveActivities.setupDefault({
    enablePushToStart: true,
    enablePushToUpdate: true
  });
  
  // Start a default live activity
  OneSignal.LiveActivities.startDefault(
    "order-tracking-456",
    {
      // Static attributes (set once)
      orderNumber: "ORD-12345",
      customerName: "John Doe"
    },
    {
      // Dynamic content (can be updated)
      status: "preparing",
      estimatedTime: "15 minutes",
      progressPercent: 25
    }
  );
}

Common Use Cases

Sports Game Tracking

if (Platform.OS === 'ios') {
  // Start tracking a live sports game
  const gameId = "nfl-game-" + Date.now();
  
  OneSignal.LiveActivities.enter(
    gameId,
    gameUpdateToken,
    (result) => {
      console.log('Started tracking game:', gameId);
    }
  );
  
  // End tracking when game is over
  setTimeout(() => {
    OneSignal.LiveActivities.exit(gameId, (result) => {
      console.log('Stopped tracking game:', gameId);
    });
  }, 3 * 60 * 60 * 1000); // 3 hours
}

Delivery Tracking

if (Platform.OS === 'ios') {
  // Setup push-to-start for delivery notifications
  OneSignal.LiveActivities.setPushToStartToken(
    "DeliveryAttributes",
    deliveryPushToken
  );
  
  // Start tracking a specific delivery
  OneSignal.LiveActivities.startDefault(
    "delivery-" + orderId,
    {
      orderNumber: orderId,
      restaurant: "Pizza Palace"
    },
    {
      status: "confirmed",
      driverName: "",
      estimatedArrival: "30 min"
    }
  );
}

Workout Session

if (Platform.OS === 'ios') {
  // Setup default live activity for workout tracking
  OneSignal.LiveActivities.setupDefault({
    enablePushToStart: false,
    enablePushToUpdate: true
  });
  
  // Start workout session
  const workoutId = "workout-" + userId + "-" + Date.now();
  
  OneSignal.LiveActivities.startDefault(
    workoutId,
    {
      workoutType: "Running",
      targetDistance: "5K"
    },
    {
      currentDistance: "0 km",
      pace: "0:00",
      duration: "00:00"
    }
  );
  
  // Update progress during workout (done via push notifications)
  // ...
  
  // End workout session
  OneSignal.LiveActivities.exit(workoutId);
}

Ride Sharing

if (Platform.OS === 'ios') {
  // Enable push-to-start for ride requests
  OneSignal.LiveActivities.setPushToStartToken(
    "RideRequestAttributes",
    rideToken
  );
  
  // When ride is confirmed, start live activity
  OneSignal.LiveActivities.startDefault(
    "ride-" + rideId,
    {
      pickup: "123 Main St",
      destination: "456 Oak Ave",
      driverName: "Sarah"
    },
    {
      status: "driver_assigned",
      eta: "5 minutes",
      vehicleInfo: "Blue Honda Civic - ABC123"
    }
  );
}

Types

interface LiveActivitySetupOptions {
  /**
   * When true, OneSignal will listen for pushToStart tokens for the OneSignalLiveActivityAttributes structure.
   */
  enablePushToStart: boolean;
  
  /**
   * When true, OneSignal will listen for pushToUpdate tokens for each start live activity that uses the
   * OneSignalLiveActivityAttributes structure.
   */
  enablePushToUpdate: boolean;
}

Platform Compatibility

All Live Activities functions are iOS-only and will:

  • Execute normally on iOS devices
  • Be ignored on Android devices (no-op)
  • Log appropriate warnings when called on Android in development builds

Always wrap Live Activities calls with platform checks for clean code:

import { Platform } from 'react-native';

if (Platform.OS === 'ios') {
  // Live Activities code here
  OneSignal.LiveActivities.setupDefault({ 
    enablePushToStart: true, 
    enablePushToUpdate: true 
  });
}

Install with Tessl CLI

npx tessl i tessl/npm-react-native-onesignal

docs

core-sdk.md

in-app-messages.md

index.md

live-activities.md

location.md

notifications.md

push-subscription.md

session.md

user-management.md

tile.json