Skip to content

feat: [SDK-5798] use heartbeat_interval_seconds from ios_params - #1815

Merged
fadi-george merged 4 commits into
new-session-eventsfrom
fadi/sdk-5798
Nov 20, 2026
Merged

fadi-george merged 4 commits into
new-session-eventsfrom
fadi/sdk-5798

Conversation

@fadi-george

@fadi-george fadi-george commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Description

One Line Summary

Use sessions.heartbeat_interval_seconds from ios_params for the session heartbeat interval.

Details

Motivation

The params response now returns the heartbeat interval, but the SDK ignored it and always used a fixed 30 minutes, so the server couldn't change it. Mirrors Android (OneSignal/OneSignal-Android-SDK#2852).

Scope

  • OSSessionService.heartbeatInterval(remoteParams:) parses sessions.heartbeat_interval_seconds, clamped to 1 minute through 1 day (matching Android). Missing, zero, negative, boolean, or non-numeric values fall back to the 1800 second default.
  • OSSessionService reads the interval from OSRemoteParamController on each heartbeat check, and the params success block re-arms a running heartbeat, so a cold launch's first visit uses the server interval instead of the default it was armed with. A heartbeat that isn't running (unfocused, or a focus about to start a new session) is not started. The hardcoded constant is removed.
  • OSRemoteParamController now synchronizes reads and writes of remoteParams (and uses dispatch_once for its singleton), since heartbeat checks read it from a background queue while a params fetch can replace it.
  • An app id change clears the in-memory remote params, so the previous app's interval isn't used before the new params arrive.
  • Unlike Android, iOS params are not persisted, so the default applies until the current launch's params fetch completes.

Testing

Unit testing

  • Parsing of valid, clamped, missing, non-positive, boolean, null, and non-numeric values.
  • Heartbeat fires at a configured 5 minute interval.
  • A params update re-arms a running heartbeat with the new interval, sends an overdue one immediately, and does not start a stopped heartbeat or one for a record about to be replaced.

OSSessionHeartbeatTests, OSSessionServiceTests, OSRemoteLoggingControllerTests, OneSignalTrackerTests, and RemoteParamsTests pass on an iOS 26.5 simulator. The params lock and app id change clear have no dedicated tests (no harness for the full init app id change path).

Manual testing

Not tested on device. Current server value (1800) matches the old default, so behavior is unchanged today.

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

🤖 Generated with Claude Code

…tbeats

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fadi-george
fadi-george requested review from abdulraqeeb33 and nan-li and removed request for abdulraqeeb33 November 19, 2026 19:07
@fadi-george
fadi-george changed the base branch from main to new-session-events November 19, 2026 19:08
fadi-george and others added 2 commits November 19, 2026 13:26
Reject boolean heartbeat intervals, synchronize OSRemoteParamController's
params, and clear them on app id change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@abdulraqeeb33 abdulraqeeb33 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stacked on new-session-events. This review is only the commits on top of that branch.

Looks good at the current server interval of 1800.

One thing to settle before that interval drops: a cold launch arms the heartbeat before ios params return, and saving params does not restart it. The first uninterrupted foreground visit stays on 1800s even after a successful fetch. The next focus picks up the server value. testIntervalChangeAppliesAfterTheCurrentWait treats the delayed apply as intended. If a shorter value should apply during that first visit, re-arm from the params success block. restartHeartbeat(continuesRecord:) already does nothing when the app is not focused.

A cold launch arms the heartbeat before params return, so the first visit
kept the default interval until its wait ended.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fadi-george

Copy link
Copy Markdown
Contributor Author

@abdulraqeeb33 Good catch, fixed in 0ffee58. The params success block now calls OSSessionService.onRemoteParamsUpdated(), which re-arms the heartbeat with the new interval, but only if one is already running. I didn't call restartHeartbeat(continuesRecord: true) directly because if params land after a focus that is about to start a new session, it would heartbeat the record being replaced.

@fadi-george
fadi-george merged commit 7649259 into new-session-events Nov 20, 2026
12 of 14 checks passed
@fadi-george
fadi-george deleted the fadi/sdk-5798 branch November 20, 2026 00:01
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.

2 participants