Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 9 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,13 @@ func application(
handleEventsForBackgroundURLSession identifier: String,
completionHandler: @escaping () -> Void
) {
if MotionTagBootstrap.handlesBackgroundURLSession(identifier: identifier) {
MotionTagBootstrap.processBackgroundSessionEvents(
identifier: identifier,
completionHandler: completionHandler
)
} else {
// Forward sessions owned by other SDKs (Firebase, …) to their handlers, or
// finish them immediately if nothing else in the app uses background sessions.
// Each session's completion handler must be called exactly once.
completionHandler()
}
// Forward every identifier unconditionally — the SDK decides internally
// which sessions are its own. If the app uses Firebase, also call its
// handleEvents(forBackgroundURLSession:) here (see the MotionTag iOS guide).
MotionTagBootstrap.processBackgroundSessionEvents(
identifier: identifier,
completionHandler: completionHandler
)
}
```

Expand Down Expand Up @@ -346,12 +342,8 @@ A version bump is **not** "just" a version bump when the changelog touches:
`UIBackgroundModes`) → update both the [bare-RN snippet above](#ios--appdelegateswift)
and the Expo plugin's Info.plist injection in `plugin/`.
- iOS bootstrap signature (`MotionTagBootstrap.bootstrap`,
`processBackgroundSessionEvents`, `handlesBackgroundURLSession`) → update
`ios/MotionTagBootstrap.swift`, the README snippet, and the plugin's
AppDelegate injection. Note: `handlesBackgroundURLSession` hard-codes the
SDK's background URL session identifier prefixes (`com.motion-tag.` /
`com.motiontag.`) — re-check them against the SDK binary on every iOS SDK
bump (`strings MotionTagSDK | grep -i session`).
`processBackgroundSessionEvents`) → update `ios/MotionTagBootstrap.swift`, the
README snippet, and the plugin's AppDelegate injection.
- Android manifest permissions or foreground-service contract → update
`android/src/main/AndroidManifest.xml`, the plugin's manifest edits, and the
Android section above.
Expand Down
13 changes: 3 additions & 10 deletions ios/MotionTagBootstrap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,10 @@ import UIKit
)
}

/// Whether the given background URL session belongs to the MotionTag SDK. Use this in
/// `application(_:handleEventsForBackgroundURLSession:completionHandler:)` to decide whether
/// to forward the event to `processBackgroundSessionEvents(identifier:completionHandler:)` or
/// to the host's other background-session owners (e.g. Expo modules, Firebase) — each session's
/// completion handler must be called exactly once, by exactly one owner.
@objc public static func handlesBackgroundURLSession(identifier: String) -> Bool {
return identifier.hasPrefix("com.motion-tag.") || identifier.hasPrefix("com.motiontag.")
}

/// Forward background URL session events so the SDK can finish background uploads on
/// cold-launch wake-ups. Call from `application(_:handleEventsForBackgroundURLSession:completionHandler:)`.
/// cold-launch wake-ups. Call from `application(_:handleEventsForBackgroundURLSession:completionHandler:)`
/// with every identifier, unconditionally — the SDK decides internally which sessions are its own
/// (matches the MotionTag iOS guide and the official Flutter SDK's AppDelegate).
@objc public static func processBackgroundSessionEvents(
identifier: String,
completionHandler: @escaping () -> Void
Expand Down
22 changes: 8 additions & 14 deletions plugin/withIosAppDelegate.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,19 @@ const BOOTSTRAP_CALL = ` // MotionTag SDK must initialise before React Native
MotionTagBootstrap.bootstrap(launchOptions: launchOptions)`

// Background uploads run in a background URL session. When iOS wakes the
// (possibly killed) app to deliver its events, they must reach the SDK —
// sessions owned by Expo modules keep going through super.
// (possibly killed) app to deliver its events, they must reach the SDK.
// Per the MotionTag iOS guide (and the official Flutter SDK's AppDelegate),
// every identifier is forwarded unconditionally — the SDK decides internally
// which sessions are its own and only calls the completion handler for those.
const BACKGROUND_SESSION_OVERRIDE = ` public override func application(
_ application: UIApplication,
handleEventsForBackgroundURLSession identifier: String,
completionHandler: @escaping () -> Void
) {
if MotionTagBootstrap.handlesBackgroundURLSession(identifier: identifier) {
MotionTagBootstrap.processBackgroundSessionEvents(
identifier: identifier,
completionHandler: completionHandler
)
} else {
super.application(
application,
handleEventsForBackgroundURLSession: identifier,
completionHandler: completionHandler
)
}
MotionTagBootstrap.processBackgroundSessionEvents(
identifier: identifier,
completionHandler: completionHandler
)
}`

/**
Expand Down
Loading