Skip to content

Conversation

@nan-li
Copy link
Contributor

@nan-li nan-li commented Dec 29, 2025

Description

One Line Summary

Retry IAM fetch when OneSignal ID becomes available if users change early in app startup.

Details

When getInAppMessagesFromServer is called early in the app lifecycle while users are changing (e.g., login is called after initialize), the OneSignal ID may not be available yet, causing the fetch to fail silently. This fix ensures in-app messages are eventually fetched by:

  • Adding OSUserStateObserver to OSMessagingController
  • Storing the subscription ID when fetch fails due to missing OneSignal ID
  • Retrying the fetch when user state changes and OneSignal ID becomes available

This prevents in-app messages from never being fetched when users are identified early in the app startup lifecycle.

Motivation

Fix bug reported when user switch early when app starts up, causing IAMs to not be fetched.

[OneSignal initialize:@"my_app_id" withLaunchOptions:launchOptions];
[OneSignal login:@"user_a"];

Scope

  • Fetching IAM

Testing

Unit testing

Manual testing

Device: iOS 18.5 simulator

  • Tested new install
  • Tested logging into new user after init (from anonymous user state)
  • Tested logging into new user after init (from an already identified user state)
  • Confirmed we won't double fetch

Affected code checklist

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
  • 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

This change is Reviewable

When getInAppMessagesFromServer is called early in the app lifecycle while users are changing (e.g., login is called after initialize), the OneSignal ID may not be available yet, causing the fetch to fail silently. This fix ensures in-app messages are eventually fetched by:

- Adding OSUserStateObserver to OSMessagingController
- Storing the subscription ID when fetch fails due to missing OneSignal ID
- Retrying the fetch when user state changes and OneSignal ID becomes available

This prevents in-app messages from never being fetched when users are identified early in the app startup lifecycle.
@nan-li nan-li force-pushed the fix/iams_not_fetched_when_users_change_early branch from a8de502 to a51d7f7 Compare December 29, 2025 17:22
@nan-li nan-li requested a review from a team December 29, 2025 17:23
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.

3 participants