Skip to content

feat(ios): recover tracking after the app is killed#2

Merged
jaymaycry merged 2 commits into
mainfrom
feat/ios-kill-recovery
Jun 2, 2026
Merged

feat(ios): recover tracking after the app is killed#2
jaymaycry merged 2 commits into
mainfrom
feat/ios-kill-recovery

Conversation

@jaymaycry

Copy link
Copy Markdown
Contributor

Why

MotionTag support reported that after the app is killed (by the user or the OS), it cannot recover and resume tracking on iOS.

Two causes, both deviations from the MotionTag iOS integration guide:

  1. SDK initialized too late. The Expo plugin injected MotionTagBootstrap.bootstrap() after startReactNative(). On a background location relaunch the SDK only initialized after the whole RN/Expo startup — too late to catch the wake-up event. The guide requires init "as early as possible" in didFinishLaunchingWithOptions.

  2. Background URL session events never reached the SDK. application(_:handleEventsForBackgroundURLSession:completionHandler:) was not wired up in the Expo path, so ExpoAppDelegate's default handler swallowed the SDK upload-session events (calling the completion handler immediately when no Expo subscriber claims them).

What

  • plugin/withIosAppDelegate.js: bootstrap is now injected as the first statement of didFinishLaunchingWithOptions; a handleEventsForBackgroundURLSession override is injected that routes MotionTag-owned sessions to the SDK and everything else to super. Block placement is idempotent across expo prebuild re-runs (existing misplaced blocks are moved).
  • ios/MotionTagBootstrap.swift: new handlesBackgroundURLSession(identifier:) — checks the SDK session-identifier prefixes (com.motion-tag. / com.motiontag., verified against the SDK 6.5.0 binary).
  • README.md: bare-RN iOS instructions updated to the routed pattern + early-init warning; SDK-bump checklist notes the hard-coded prefixes; Android bare-RN snippet fixed to init before loadReactNative.

Verification

  • react-native-motiontag pod target compiles (incl. new bootstrap API)
  • Generated AppDelegate verified across repeated expo prebuild runs (placement, idempotency, upgrade path)
  • Full example-app build is blocked by a pre-existing ExpoModulesCore / "no such module 'React'" environment issue — proven unrelated via counterfactual build on unmodified main (identical failure)
  • Device test (kill app → move → tracking resumes) still pending

🤖 Generated with Claude Code

jaymaycry and others added 2 commits June 2, 2026 16:22
After the app was killed by the user or the OS, tracking never resumed.
Two causes, both against the MotionTag iOS integration guide:

- The Expo plugin injected MotionTagBootstrap.bootstrap() after
  startReactNative(), so on a background location relaunch the SDK only
  initialized after the whole RN/Expo startup — too late to catch the
  wake-up event. It is now the first statement of
  didFinishLaunchingWithOptions.
- application(_:handleEventsForBackgroundURLSession:completionHandler:)
  was never wired up in the Expo path, so the SDK's background upload
  events were swallowed by ExpoAppDelegate's default handler. The plugin
  now injects an override that routes MotionTag-owned sessions (new
  MotionTagBootstrap.handlesBackgroundURLSession check) to the SDK and
  everything else to super.

Reported by MotionTag support during their iOS integration testing.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The MotionTag Android guide requires initialisation as early as possible
in Application.onCreate, and the Expo plugin already injects the bootstrap
before loadReactNative — the bare-RN README snippet showed it after,
contradicting both.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jaymaycry jaymaycry merged commit e5834b5 into main Jun 2, 2026
1 check passed
jaymaycry added a commit that referenced this pull request Jun 2, 2026
…ting

PR #2 was merged with a merge commit, so release-please counted both the
merge commit (resolved via the PR title) and the underlying feat commit as
separate changelog entries. Keep the one linking to the actual commit.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jaymaycry jaymaycry deleted the feat/ios-kill-recovery branch June 2, 2026 17:05
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