widgetPushTokens static method

Future<Map<String, String>> widgetPushTokens()

The APNs push tokens WidgetKit issued for widgets declaring push: true, keyed by widget name.

Only the widget extension is told these tokens, and it cannot reach your server — it stores them for the app to collect. Read this on launch and on resume, and register whatever it returns:

final tokens = await MosaicBridge.widgetPushTokens();
for (final entry in tokens.entries) {
  await myApi.registerWidgetToken(widget: entry.key, token: entry.value);
}

Your server then pushes {"aps":{"content-changed":true}} to a token with apns-push-type: widgets and topic <bundle-id>.push-type.widgets, which reloads that widget's timeline while the app is closed.

Empty until WidgetKit issues a token — it does so once a widget is placed, and not at all in the simulator. iOS 26+ only; returns empty on Android, which has no widget-push equivalent.

Implementation

static Future<Map<String, String>> widgetPushTokens() async {
  try {
    final tokens = await _channel.invokeMapMethod<String, String>(
      'widgetPushTokens',
      {'appGroupId': _appGroupId},
    );
    return tokens ?? const {};
  } on MissingPluginException {
    // Android has no widget-push equivalent, so its host may not implement
    // this at all. Absence of tokens is the correct answer, not an error.
    return const {};
  } on PlatformException {
    return const {};
  }
}