Skip to content
Back to archipelago.banuacoder.com

Feature SDKs (Pro)

push_notification_onesignal Pro ​

Tier
Proversion 1.5.3
Command
archipelago generate push_notification_onesignal
Generates
  • features/push_notification/push_notification_onesignal_impl
Generates first
push_notification_sdkwhen needed and missing, so there is nothing to install first
Depends on
shared_app_config, shared_consentgenerate these first

push_notification_onesignal is a Pro feature brick. It adds the package: push_notification_onesignal_impl. It generates push_notification_sdk first if the workspace does not have it yet. No other brick depends on it.

OneSignal provider implementation for push_notification_sdk. Generates push_notification_onesignal_impl — a PushNotificationProviderHandler backed by the OneSignal Flutter SDK v5.x — and wires it into the same DI chain as the free FCM provider. Needs push_notification_sdk and generates it first when it is missing, without FCM and so without any Firebase dependency.

When to use it ​

Choose it when you send push through OneSignal. It works with FCM or alone, and without FCM there is no Firebase dependency. Tokens are then OneSignal subscription IDs, not FCM tokens, so any backend code that stores FCM tokens needs a change.

Skip it if you only use FCM: the free push_notification_sdk already has that provider. The hooks add the iOS push entitlement, the remote-notification background mode and the Android POST_NOTIFICATIONS permission. They do not touch Gradle. You still follow OneSignal's own platform setup, such as an APNs key for iOS. The handler stays dormant until the user gives consent for the configured purpose, marketing by default.

Variables ​

VariableTypeDefaultDescription
oneSignalAppIdstring''Your OneSignal App ID (Settings > Keys & IDs in the OneSignal dashboard). Not a secret. post_gen writes it as ONESIGNAL_APP_ID into every shared/app_config/.env* file (left empty when you give none, with a warning, and the handler then refuses to start OneSignal); edit the flavor files to give each flavor its own OneSignal app.
consentPurposeenum (marketing, analytics, diagnostics, targeting, none)marketingThe consent purpose that gates the OneSignal SDK. It stays dormant until the user grants it. none starts OneSignal without a consent gate, so the OS notification permission is the only opt-in.
isForMonorepobooleantrueWhether this is being generated as part of a monorepo.

Install ​

Interactive ​

bash
archipelago generate push_notification_onesignal

Non-interactive (CI) ​

bash
archipelago generate push_notification_onesignal --config my_config.json

When the project has no push_notification_sdk package, pre_gen generates it first with includeFcm: false: no push_notification_fcm_impl, no firebase_messaging, no Firebase bootstrap and no google-services plugin. A project that already has FCM keeps it, and both providers run side by side. Before 1.4.0 the SDK was generated with FCM, so OneSignal always brought Firebase along.

OneSignal only (no Firebase) ​

Create the project with isUsingFirebase: false and no push starter, then add the brick:

bash
archipelago generate push_notification_onesignal --config onesignal.json
json
{ "oneSignalAppId": "00000000-0000-0000-0000-000000000000", "consentPurpose": "marketing" }

On Android, OneSignal's own SDK delivers the pushes, so no google-services.json is needed. On iOS you still set up APNs in the OneSignal dashboard.

The App ID per flavor ​

The handler does not hold the App ID in source. post_gen declares ONESIGNAL_APP_ID in shared/app_config (AppEnv.onesignalAppId) and writes oneSignalAppId, or a placeholder, into .env.development, .env.staging, .env.production and .env. OneSignalRegisterModule builds a OneSignalConfig from AppEnv and the chosen consentPurpose, and the handler takes that config. To use a different OneSignal app per flavor, edit the value in each .env.<flavor> and run build_runner (envied compiles it in).

Upgrading from 1.3.x ​

push_notification_onesignal_impl now depends on app_config, and OneSignalPushNotificationHandler takes a OneSignalConfig. The brick does not overwrite a package you changed. Either regenerate the package after merging, or in your copy: add the app_config dependency, move the App ID from onesignal_push_notification_handler.dart into ONESIGNAL_APP_ID, and provide OneSignalConfig from a @module as the generated register_module.dart does.

Relationship to push_notification_sdk ​

push_notification_sdk is the push feature (contract PushNotificationSDK/PushNotificationProviderHandler, orchestrator PushNotificationSDKImpl, and — if includeFcm is true — the FCM provider push_notification_fcm_impl). push_notification_onesignal is an additive vendor provider, exactly like analytics_sdk's vendor bricks: it adds PushNotificationProvider.oneSignal (already present in the shared PushNotificationProvider enum). It can be the only provider (SDK generated with includeFcm: false) or run next to FCM; the orchestrator discovers all registered PushNotificationProviderHandlers via getIt.getAll().

Generated Package ​

PackagePurpose
push_notification_onesignal_implPushNotificationProviderHandler implementation backed by onesignal_flutter

Generated Structure ​

text
features/
└── push_notification/
    └── push_notification_onesignal_impl/
        └── lib/src/
            ├── onesignal_push_notification_handler.dart
            └── di/

Public API ​

You don't call this package directly — go through the shared PushNotificationSDK from push_notification_sdk, which fans out to every registered provider:

dart
final push = getIt<PushNotificationSDK>();
await push.requestPermission();
final token = await push.getToken(); // returns whichever provider(s) are registered

OneSignalPushNotificationHandler itself implements the same PushNotificationProviderHandler contract FCM does: requestPermission(), getPermissionStatus(), getToken(), subscribeToTopic()/unsubscribeFromTopic(), foregroundStream, tapStream, clearAll().

Notification policy (since 1.3.0) ​

Every foreground message passes the notification policy from push_notification_sdk (1.3.1 or later) before OneSignal displays it. See the decision flow.

  1. The will-display listener calls event.preventDefault() at once, which holds the OneSignal banner while the policy runs.
  2. Suppressed messages (no marketing consent, quiet hours, cap reached) are never shown and never emitted.
  3. Shown messages are emitted on foregroundStream. Only messages without publicTitle get display(): untagged and tier: marketing messages.

Untagged messages are unchanged. A message without a tier (in OneSignal's "Additional Data") keeps the OneSignal banner and its real title and body, exactly as before the policy. Redaction is opt-in: messages the sender marks sensitive (explicit tier: critical / tier: transactional, or sensitive: "true") get no OneSignal banner in the foreground, because the device cannot give that banner lock-screen-safe text. The app displays them from foregroundStream with publicTitle / publicBody as the lock-screen version. Background deliveries are not affected.

A sensitive message with detail_title or detail_body in its Additional Data (the detail split) also gets no OneSignal banner: the app shows the detail text, and the OneSignal heading and content become publicTitle / publicBody. A non-sensitive message with these keys keeps its banner and its heading and content, as before the split. To send this split from your server, see Notification policy on your backend.

Topics are simulated via tags ​

OneSignal has no first-class "topic" concept. subscribeToTopic(topic) sets a tag topic_<name> = "true"; unsubscribeFromTopic(topic) removes that tag. Build server-side segments on these tags if you rely on OneSignal-side targeting.

DI & Wiring ​

  • PushNotificationOnesignalImplPackageModule registers OneSignalPushNotificationHandler as @Named('oneSignal') @LazySingleton(as: PushNotificationProviderHandler), so it coexists with the FCM handler.
  • Ordering matters: PushNotificationGlobalModule.init() (the orchestrator) eagerly calls getAll<PushNotificationProviderHandler>(), so every handler must already be registered when it runs. post_gen first patches push_notification_impl/pubspec.yaml's archipelago: di_modules: depends_on: list to add push_notification_onesignal_impl, then registers the OneSignal module in injector.dart; the manifest-driven resolver uses that depends_on graph to order the injector so every handler is registered before the orchestrator, and regeneration with monorepo_toolkit generate host-registry keeps that order.
  • OneSignalRegisterModule provides the OneSignalConfig (App ID from AppEnv, consent purpose from the brick var). OneSignal's Flutter SDK itself is a static API surface (OneSignal.*), so there is no SDK instance to provide.
  • Consent-gated: the handler calls OneSignal.consentRequired(true) before initialize() and follows the configured consentPurpose (default ConsentPurpose.marketing) from ConsentGateRegistry, so OneSignal stays dormant until the user consents. With consentPurpose: none it starts without a gate. Init failures are caught and logged, never rethrown.
  • When the SDK has no FCM, PushNotificationGlobalModule has no depends_on; post_gen adds push_notification_onesignal_impl so the injector registers OneSignal before the orchestrator.

Dependencies ​

onesignal_flutter ^5.6.7, app_config, consent_api, and push_notification_api from push_notification_sdk 1.3.1 or later (for NotificationPolicyRegistry and opt-in redaction).

Platform Setup ​

The hooks add ios/Runner/Runner.entitlements (aps-environment), the remote-notification background mode in Info.plist and POST_NOTIFICATIONS in the Android manifest. They do not touch Gradle. You must still, per OneSignal's own Flutter SDK setup:

  • Create a OneSignal app in the OneSignal dashboard and obtain its App ID.
  • Supply the App ID at generation time via oneSignalAppId; the handler calls OneSignal.initialize(appId) itself from its constructor, and every handler method waits for it before touching OneSignal. If you left it empty, set ONESIGNAL_APP_ID in each .env.<flavor> and run build_runner.
  • Follow OneSignal's platform setup (APNs key for iOS; for Android, OneSignal's SDK delivers pushes, and a Firebase Server Key is needed only if you also run FCM) per https://documentation.onesignal.com/docs/flutter-sdk-setup.

On iOS the brick leaves these steps to you:

  • Upload your APNs key (.p8, Key ID, Team ID) in the OneSignal dashboard, and in the Firebase console if the project also uses FCM. Without the key, no push reaches an iOS device.
  • Add the Push Notifications capability to the App ID, and make sure that your provisioning profiles include it.
  • Runner.entitlements sets aps-environment to development for every build configuration. An App Store or TestFlight export signs with the distribution profile, which sets production. If you sign release builds another way, set production yourself.
  • If a build configuration already has CODE_SIGN_ENTITLEMENTS, the brick keeps your value. Add aps-environment to that file yourself.
  • No Notification Service Extension target is added. Without one, images in a push and OneSignal confirmed delivery do not work.

Limitations ​

  • clearAll() opts the device out of push (pushSubscription.optOut()) but deliberately does not close its internal stream controllers or unregister its OneSignal listeners — this handler is a process-lifetime LazySingleton, so closing them would permanently break foregroundStream/tapStream after the first logout. A brief window between optOut() and re-login can still deliver events; apps with strict requirements should unregister/re-register listeners around the auth cycle themselves.
  • Without FCM there is a single provider: PushNotificationProvider.oneSignal. Tokens are OneSignal subscription IDs, not FCM tokens.

Changelog ​

Run archipelago brick info push_notification_onesignal to see the latest published version. Enterprise customers can read the full CHANGELOG.md in the brick source repository.