Skip to content

refactor: route identifier reads through OneSignalIdentifiers#1667

Open
nan-li wants to merge 5 commits into
mainfrom
nan/identifier-accessors
Open

refactor: route identifier reads through OneSignalIdentifiers#1667
nan-li wants to merge 5 commits into
mainfrom
nan/identifier-accessors

Conversation

@nan-li
Copy link
Copy Markdown
Contributor

@nan-li nan-li commented May 30, 2026

Description

One Line Summary

Consolidate vital OneSignal SDK identifier accessors (app_id, subscription_id) into a single source so future fallback logic (cross-process / locked-state) can be added in one place.

Details

Motivation

The SDK currently reads OSUD_APP_ID and OSUD_PUSH_SUBSCRIPTION_ID from OneSignalUserDefaults at ~20 ad-hoc call sites across 8 modules, with three different in-memory caches (OneSignalConfigManager._appId, OSNotificationsManager._pushSubscriptionId, _user.pushSubscriptionModel.subscriptionId). This makes it difficult to add a coordinated fallback (e.g. for the iOS prewarm bug where UserDefaults is unreadable before first unlock). Consolidating the accessors into OneSignalIdentifiers (durable reads) and OneSignalConfig (readiness predicate) sets up a single place for that follow-up.

Scope

Three commits:

  1. 21ed8132 — Add OneSignalIdentifiers.storedAppId / subscriptionId in OneSignalOSCore. Migrate 6 durable-read sites. Link OneSignalOSCore into OneSignalNotifications and OneSignalExtension targets. Drop now-dead OSUD_APP_ID write to initStandard.

  2. 07891381 — Drop redundant OSNotificationsManager._pushSubscriptionId static cache + setter; the model's didSet already persists. Removes drift risk and one call in OSUserExecutor.

  3. eb1a4213 — Replace OneSignalConfigManager with OneSignalConfig + OneSignalIdentifiers.currentAppId (thread-safe via NSLock). Migrate ~30 call sites across 8 modules. Link OneSignalOSCore into OneSignalInAppMessages, OneSignalLocation, OneSignalOutcomes.

Behavior change to note: OneSignal.m's prevAppId reads previously hit initStandard, now hit initShared via the accessor. Behavior-preserving for any install on SDK 2.13.0+ (Dec 2019, commit 7240697d) — handleAppIdChange has dual-written OSUD_APP_ID to both stores ever since.

Not changed: any externally-observable behavior. No public API changes.

Testing

Unit testing

Existing tests updated for the renamed OneSignalConfigManager.setAppId(...)OneSignalIdentifiers.currentAppId = ....

Manual testing

Built and ran the dev app on a physical device with the SDK from source. Verified OneSignal.User.onesignalId and OneSignal.User.pushSubscription.id return the expected real values. Confirmed via temporary debug logs that OneSignalIdentifiers.storedAppId / subscriptionId return the persisted values at runtime.

Affected code checklist

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries (NSE-side reads now go through OneSignalIdentifiers)
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
  • I have reviewed this PR myself, ensuring it meets each checklist item

nan-li added 2 commits May 30, 2026 16:21
Add OneSignalIdentifiers in OneSignalOSCore with storedAppId and
storedSubscriptionId accessors backed by shared UserDefaults. Migrate
six call sites; drop the now-dead OSUD_APP_ID write to initStandard.
OSSubscriptionModel.subscriptionId.didSet already persists to UserDefaults
on every change, so the static _pushSubscriptionId cache and its setter
were duplicating state with drift risk. Route the one caller through
OneSignalIdentifiers.subscriptionId directly. Drop the now-unused
OSUserExecutor.setPushSubscriptionId call too — the model hydration on
the line above already triggers the persistence path.
Comment thread iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj
@nan-li nan-li force-pushed the nan/identifier-accessors branch 2 times, most recently from eb1a421 to 16a42e3 Compare May 31, 2026 22:57
nan-li added 2 commits May 31, 2026 17:51
…gnalIdentifiers.currentAppId

OneSignalConfigManager held two distinct things in one ObjC class in
OneSignalCore: (1) the in-memory app_id state, and (2) the SDK-readiness
predicate `shouldAwaitAppIdAndLogMissingPrivacyConsent`. Split into two
Swift classes in OneSignalOSCore so all identifier accessors live in one
module:

- `OneSignalIdentifiers.currentAppId` — in-memory app_id, replaces
  `OneSignalConfigManager.getAppId/setAppId`. Sits next to the existing
  `storedAppId` (persisted) and `subscriptionId` (persisted) accessors.
- `OneSignalConfig.shouldAwaitAppIdAndLogMissingPrivacyConsent` — same
  semantics, now reads `OneSignalIdentifiers.currentAppId` internally.

Migrate ~30 call sites across OneSignalCore (umbrella), OneSignalOSCore,
OneSignalUser, OneSignalLiveActivities, OneSignalNotifications, OneSignal-
Location, OneSignalInAppMessages, OneSignalOutcomes, and the main OneSignal
target. Link OneSignalOSCore.framework into OneSignalInAppMessages, One-
SignalLocation, and OneSignalOutcomes targets (they didn't previously).
Those subspecs / SPM wrappers ship binaries that now link
OneSignalOSCore.framework. Without the declaration, NSE-only integrations
via CocoaPods or SPM wouldn't embed it and dyld would fail to load the
NSE binary on the first push.
@nan-li nan-li force-pushed the nan/identifier-accessors branch from fefada6 to 898cde1 Compare June 1, 2026 00:52
@nan-li
Copy link
Copy Markdown
Contributor Author

nan-li commented Jun 1, 2026

@claude review

Comment thread iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OneSignalConfig.swift Outdated
Comment thread iOS_SDK/OneSignalSDK/OneSignalInAppMessagesTests/IAMIntegrationTests.swift Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant