Skip to content

feat(admob): wire real BannerView load for v2.5.2 (task #3) - #143

Merged
wei18 merged 4 commits into
mainfrom
feat/admob-banner-wiring-v2.5.2
May 26, 2026
Merged

wei18 merged 4 commits into
mainfrom
feat/admob-banner-wiring-v2.5.2

Conversation

@wei18

@wei18 wei18 commented May 26, 2026

Copy link
Copy Markdown
Owner

Summary

Implements v2.5.2 AdMob banner wiring (replaces `LiveAdMobBridge.loadBanner()` stub). Unblocks the real-device test-ad checklist in issue #132.

Changes

  • App/Info.plist: `GADApplicationIdentifier` = Google test app ID (`ca-app-pub-3940256099942544~1458002511`)
  • LiveAdMobBridge.swift: real `BannerView` load via AdMob 13.x Swift API; `#if DEBUG` test ad unit / `#else` production
    • `BannerLoadDelegate` actor with `OSAllocatedUnfairLock` single-resume guard
    • Strong-hold delegates in `inFlightDelegates` (BannerView.delegate is weak — classic footgun)
    • `AdBannerHandle` (UUID-only) stays in MonetizationCore — no GoogleMobileAds type leaks across protocol seam

3 commits, +213/-6 LOC across 3 files (Info.plist + bridge + impl-notes).

Isolation contract (foundations §9.1)

`rg "^import GoogleMobileAds" Packages/` = 1 file (LiveAdMobBridge.swift only). Tighter than the documented "≤2" target.

Code Reviewer verdict: APPROVE-WITH-NITS

0 must-fix. 6 nits, ranked by significance:

Nit Recommended action
N1 — Production IDs (`ca-app-pub-8986741979385138/3172412685` + `~8581337790`) live in `#else` branch + Info.plist comment. Risk: accidental Release build before v2.5.3 swap Replace `#else` constant with `fatalError("REPLACE_IN_v2.5.3")` so any unintended Release fails loudly. Inline-fix pre-merge recommended.
N2 — Info.plist `GADApplicationIdentifier` lacks DEBUG/Release pivot — single static test value Document in `v2.5-readiness.md §v2.5.3` as paired-flip checklist item
N3 — `withCheckedThrowingContinuation` not wrapped in `withTaskCancellationHandler` Cosmetic per CR; best-practice concurrency hygiene
N4 — `liveBanners` never cleared on success (intentional per impl-notes D3, awaiting future `dispose(handle:)` API) Add `// TODO(v2.5.x): dispose accessor` marker
N5 — `Set` removal via `.filter` rebuilds — `.remove(_:)` is the natural API Cosmetic
N6 — Audit grep should use `^import GoogleMobileAds` (stricter) Update methodology doc

CR praise

  • Single-resume guard via `OSAllocatedUnfairLock` matches house style
  • Strong-hold delegates correctly addresses weak BannerView.delegate footgun
  • Surgical scope (Karpathy §3 satisfied)
  • Comment density at every non-obvious decision

Pre-merge user-owned config (per CR §pre-merge)

  1. AdMob console: test app ID needs no console registration (Google universal). ✓
  2. ASC App ID match: not needed for v2.5.2 test build (deferred to v2.5.3)
  3. TestFlight build for v2.5.2 verification: prefer Debug-configured archive
  4. `Package.resolved` GoogleMobileAds 13.x version pinned — verify via one CI build

Closes

Test plan

  • CI `swift test` (full suite) → exit 0
  • Decide on N1 fix (`fatalError` guard or accept current placeholder)
  • After merge: user runs v2.5.2 real-device checklist per `docs/v2/v2.5-readiness.md`

🤖 Generated with Claude Code

wei18 and others added 4 commits May 26, 2026 11:11
Google Mobile Ads 13.x crashes early in MobileAds.shared.start() if
GADApplicationIdentifier is absent from Info.plist. v2.5.2 uses Google's
universal TEST App ID; v2.5.3 (user-owned) swaps to production.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
Replace the v2.3.4 stub with an actual AdMob 13.x banner fetch:
- Construct BannerView(adSize: AdSizeBanner) on the main actor
- Resolve key window's rootViewController from connected scenes
  (required only for click-through presentation; load succeeds without)
- Bridge BannerViewDelegate's terminal callbacks into a single
  CheckedThrowingContinuation, single-resume-guarded against double-fire
- Retain live BannerView in a UUID-keyed dict so future UIViewRepresentable
  plumbing (out of v2.5.2 scope) can fetch it via a UIKit-typed accessor
  that stays internal to AdsAdMob (foundations §9.1)
- Ad unit ID: #if DEBUG pivot — test ID 2934735716 in Debug, production
  3172412685 in Release. Single grep target for the v2.5.3 swap, matching
  the same pattern used for GADApplicationIdentifier in Info.plist.

Isolation contract intact: exactly 1 `import GoogleMobileAds` directive
(LiveAdMobBridge.swift). Existing 8 BannerLoadTests against the
FakeAdMobBridge protocol seam unchanged and all pass.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
N1 — Replace #else production ad unit ID constant with a fatalError-guarded
computed property (REPLACE_IN_v2.5.3). Scrub production App ID literal from
App/Info.plist comment; replaced with doc-reference-only pointer to
docs/v2/v2.5-readiness.md §v2.5.3. Plist value unchanged (still Google test).

N3 — Wrap loadBanner() continuation in withTaskCancellationHandler. Reuses
the existing OSAllocatedUnfairLock<Bool> single-resume guard on
BannerLoadDelegate via a new cancel() method that routes through resumeOnce
with CancellationError. A local OSAllocatedUnfairLock<BannerLoadDelegate?>
holder bridges the cancel closure to the delegate constructed inside the
continuation. Cancel-vs-callback races resolve via the existing hasResumed
flag — no new lock introduced.

N4 — Add TODO(v2.5.x) marker above the liveBanners insert site documenting
the planned dispose(handle:) accessor and the intentional retain-for-handle-
lifetime behavior (per impl-notes D3).

Verified: swift build clean; swift test --filter BannerLoad (8/8 pass);
swift test --filter AdMob (26/26 pass). Isolation audit: 1 import directive
in LiveAdMobBridge.swift; 0 occurrences of production app ID across
Packages/ and App/. N2 / N5 / N6 deferred.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@wei18

wei18 commented May 26, 2026

Copy link
Copy Markdown
Owner Author

CR nits applied — commit 120ac65

3 nits inline-fixed via subagent:

  • N1 ✅ Production ad unit ID #else branch replaced with fatalError("REPLACE_IN_v2.5.3: …") — any unintended Release build fails loudly at first ad load. App/Info.plist production-ID comment also scrubbed.
  • N3 ✅ loadBanner() continuation now wrapped in withTaskCancellationHandler; cancel path reuses existing OSAllocatedUnfairLock<Bool> single-resume guard via new BannerLoadDelegate.cancel() method. No new lock introduced.
  • N4 ✅ liveBanners insertion site annotated with // TODO(v2.5.x): dispose(handle:) accessor explaining intentional retention.

Diff: +89/-26 LOC across 3 files (LiveAdMobBridge.swift + App/Info.plist + impl-notes).

Validation

  • swift test --filter BannerLoad → 8/8 pass
  • swift test --filter AdMob → 26/26 pass across 4 suites
  • Isolation audit: rg "import GoogleMobileAds" Packages/ → 1 actual import (internal import GoogleMobileAds in LiveAdMobBridge.swift only)
  • Production-ID scrub: rg "8986741979385138" Packages/ App/ → 0 matches

Subagent observation worth tracking (for N6 follow-up)

Audit grep pattern in CR N6 (^import GoogleMobileAds) won't match internal import GoogleMobileAds. Better: ^(internal |private |public |@_implementationOnly |@preconcurrency )*import GoogleMobileAds. To be addressed in N6 deferred work.

Remaining deferred (post-merge)

  • N2 GADApplicationIdentifier DEBUG/Release pivot — doc-only update to v2.5-readiness.md §v2.5.3
  • N5 Set<BannerLoadDelegate> removal style — cosmetic
  • N6 audit grep pattern — methodology doc update (with improved regex per above)

Ready to merge.

@wei18
wei18 merged commit c681545 into main May 26, 2026
@wei18
wei18 deleted the feat/admob-banner-wiring-v2.5.2 branch May 26, 2026 04:26
wei18 added a commit that referenced this pull request May 26, 2026
Round-2 CR nits from PR #143:

- N2 (v2.5-readiness.md): split v2.5.3 into "Production AdMob ID paired flip"
  + "Submission steps" subsections; the paired flip checklist makes the
  asymmetric Info.plist / LiveAdMobBridge.swift swap impossible to forget.
- N5 (LiveAdMobBridge.swift): replace ObjectIdentifier-filter with
  set.remove(_:) — BannerLoadDelegate inherits NSObject so Set uses NSObject
  identity hashing (hash + isEqual:) directly. Cosmetic, behaviour-identical.
- N6 (plan.md + v2.5-readiness.md): tighten isolation-audit grep to
  '^(internal |private |public |@_implementationOnly |@preconcurrency )*import GoogleMobileAds'
  so it does not false-positive on doc comments mentioning the import. Also
  correct stale "2 檔" claims — AdMobBridge.swift is protocol-only and does
  not import the SDK; LiveAdMobBridge.swift is the single import site.
wei18 added a commit that referenced this pull request May 26, 2026
… (#148)

Round-2 CR nits from PR #143:

- N2 (v2.5-readiness.md): split v2.5.3 into "Production AdMob ID paired flip"
  + "Submission steps" subsections; the paired flip checklist makes the
  asymmetric Info.plist / LiveAdMobBridge.swift swap impossible to forget.
- N5 (LiveAdMobBridge.swift): replace ObjectIdentifier-filter with
  set.remove(_:) — BannerLoadDelegate inherits NSObject so Set uses NSObject
  identity hashing (hash + isEqual:) directly. Cosmetic, behaviour-identical.
- N6 (plan.md + v2.5-readiness.md): tighten isolation-audit grep to
  '^(internal |private |public |@_implementationOnly |@preconcurrency )*import GoogleMobileAds'
  so it does not false-positive on doc comments mentioning the import. Also
  correct stale "2 檔" claims — AdMobBridge.swift is protocol-only and does
  not import the SDK; LiveAdMobBridge.swift is the single import site.
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