iOS

Live Activities on iOS with the Flutter SDK

When using the Flutter SDK, Live Activities can be managed in two different ways:

  1. Flutter/Dart API – Allows you to retrieve active Live Activities, subscribe them to the backend, and (if provided by native code) send push token updates, all directly from Dart.
  2. 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 and PushTokenUpdates) cannot be triggered from Flutter.

This must be implemented in the native iOS layer, which then sends tokens to your backend for targeting Live Activities.


Flutter/Dart API Reference

All methods are asynchronous and return results via Future callbacks.

For this example, we’ll use the attribute name: TimerWidgetAttributes.


Get List of Active Live Activities

Retrieves all active Live Activities currently associated with the device.

Indigitall.getListLiveActivities(
  onSuccess: (list) {
    print("Active Live Activities: $list");
  },
  onError: (error) {
    print("Error fetching live activities: ${error.message}");
  },
);


Subscribe to Live Activities

Sends a list of Live Activities the device is subscribed to, so the backend can target them with push updates.

final activities = [
  {
    "liveActivityExternalId": "order_123",
    "iosAttributesType": "TimerWidgetAttributes"
  }
];

Indigitall.subscribeToLiveActivities(
  activities,
  onSuccess: () {
    print("Successfully registered live activities");
  },
  onError: (error) {
    print("Error subscribing to live activities: ${error.message}");
  },
);


Set PushToStart Token Updates

Native-only limitation: The actual token retrieval must be done in iOS native code, then passed to this method from Flutter.

final tokenParams = {
  "token": "hexadecimal_push_to_start_token",
  "iosAttributesType": "TimerWidgetAttributes"
};

Indigitall.setPushToStartTokenUpdates(
  tokenParams,
  onSuccess: () {
    print("PushToStart token sent successfully");
  },
  onError: (error) {
    print("Error sending PushToStart token: ${error.message}");
  },
);


Set Push Token Updates (Advanced)

Updates the push token for an already running Live Activity.

final tokenUpdateParams = {
  "token": "hexadecimal_push_token",
  "liveActivityExternalId": "order_123"
};

Indigitall.setPushTokenUpdates(
  tokenUpdateParams,
  onSuccess: () {
    print("Push token update sent successfully");
  },
  onError: (error) {
    print("Error updating push token: ${error.message}");
  },
);


Push Reception Callback

Registers a callback to handle incoming push notifications, including Live Activity events.

Indigitall.onMessageReceived(
  onSuccess: (pushData) {
    print("Push received: $pushData");

    if (pushData["pushType"] == "LIVE_ACTIVITY") {
      switch (pushData["liveActivityEventType"]) {
        case "START":
          print("Live Activity started: $pushData");
          break;
        case "UPDATE":
          print("Live Activity updated: $pushData");
          break;
        case "END":
          print("Live Activity ended: $pushData");
          break;
      }
    }
  },
  onError: (error) {
    print("Push reception error: ${error.message}");
  },
);


Example: Full Live Activities Workflow in Flutter (iOS)


// 1. Get current active Live Activities
Indigitall.getListLiveActivities(
  onSuccess: (liveActivities) {
    print("Active Live Activities: $liveActivities");

    // 2. Subscribe them to the backend
    Indigitall.subscribeToLiveActivities(
      liveActivities.map((la) => la.toJson()).toList(),
      onSuccess: () {
        print("Live activities subscribed successfully");
      },
      onError: (error) {
        print("Subscription error: ${error.message}");
      },
    );
  },
  onError: (error) {
    print("Error fetching live activities: ${error.message}");
  },
);

// 3. Set PushToStart token (token must come from native iOS code)
final pushToStartParams = {
  "token": "hexadecimal_push_to_start_token",
  "iosAttributesType": "TimerWidgetAttributes"
};
Indigitall.setPushToStartTokenUpdates(
  pushToStartParams,
  onSuccess: () {
    print("PushToStart token sent");
  },
  onError: (error) {
    print("Error sending PushToStart token: ${error.message}");
  },
);

// 4. Set Push token updates (token must come from native iOS code)
final pushTokenParams = {
  "token": "hexadecimal_push_token",
  "liveActivityExternalId": "order_123"
};
Indigitall.setPushTokenUpdates(
  pushTokenParams,
  onSuccess: () {
    print("Push token update sent");
  },
  onError: (error) {
    print("Error updating push token: ${error.message}");
  },
);

// 5. Listen for push events
Indigitall.onMessageReceived(
  onSuccess: (pushData) {
    print("Push received: $pushData");

    if (pushData["pushType"] == "LIVE_ACTIVITY") {
      switch (pushData["liveActivityEventType"]) {
        case "START":
          print("Live Activity started: $pushData");
          break;
        case "UPDATE":
          print("Live Activity updated: $pushData");
          break;
        case "END":
          print("Live Activity ended: $pushData");
          break;
      }
    }
  },
  onError: (error) {
    print("Push reception error: ${error.message}");
  },
);