From 04e702a99b8d47eb581e9787f1472c63a8f8ab23 Mon Sep 17 00:00:00 2001 From: joywayer Date: Mon, 29 Jun 2026 08:58:00 +0800 Subject: [PATCH] =?UTF-8?q?Phase=201.F:=20WebView=20=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E4=BB=8E=20file://=20=E8=BF=81=E5=88=B0=20ylgame://h5=20?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=20scheme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 为未来 Cocos 子游戏 H5 build 适配铺路(file:// 下 Cocos XHR/fetch 受 null-origin 限制几乎必踩坑),同时保留大厅 + 子游戏跨页 localStorage 共享语义(用单虚拟 host `h5` 让所有 H5 same-origin)。 变更: - 新增 AppSchemeHandler(WKURLSchemeHandler 单例 + Range/MIME/异步 IO/ 取消语义;闭包只携 Sendable ObjectIdentifier,不捕获 task) - SandboxPaths 加 lobbyIndexAppURL / subGameIndexAppURL builders - BridgedWebView 注册 scheme handler(WKWebView init 前) - WebContainerViewController / SubGameViewController 的 loadFileURL → webView.load(URLRequest),OverlayViewController 不变 文档: - Plan 新增 Phase 1.F (1.18-1.21) + ADR-010 决策记录 + 进度勾选 - Design 新增 §7.6 包含 URL 结构 / 实现要点 / 等价性表 / Cocos 预检脚本 - Contract §0.2 / §4.1 / §10 验收清单同步切换说明(H5 可观察差异: location.protocol "file:" → "ylgame:",项目方已 grep 确认现网 H5 不依赖此字面) 存量影响:file:// → ylgame:// origin 切换时老用户 localStorage 一次性 清零,已与项目方确认业务可接受、不做迁移补偿。 BuildProject 通过。Plan 进度已勾选 1.18/1.19/1.20。 Co-Authored-By: Claude Opus 4.7 --- docs/Development-Plan.md | 85 +++- docs/H5-Native-Contract.md | 15 +- docs/H5-Native-Implementation-Design.md | 127 ++++++ ylgamehall/Source/Resource/SandboxPaths.swift | 26 ++ .../Source/WebView/AppSchemeHandler.swift | 415 ++++++++++++++++++ .../Source/WebView/BridgedWebView.swift | 12 + .../WebView/SubGameViewController.swift | 12 +- .../WebView/WebContainerViewController.swift | 11 +- 8 files changed, 686 insertions(+), 17 deletions(-) create mode 100644 ylgamehall/Source/WebView/AppSchemeHandler.swift diff --git a/docs/Development-Plan.md b/docs/Development-Plan.md index 9b2a71e..16dc723 100644 --- a/docs/Development-Plan.md +++ b/docs/Development-Plan.md @@ -319,6 +319,40 @@ Contract Design Plan(本文档) - BuildProject 通过 - [ ] **1.17** 把渠道目录里临时填入的 demo 值 + 一个 demo H5 跑通 / 真机验证完整 1.10-1.16 链路 +##### 1.F WKURLSchemeHandler 迁移(Cocos 适配前置 + 跨页 localStorage 共享,ADR-010) + +> Phase 1.F 是对 Phase 1.14.d / Phase 6.x `loadFileURL` 路径的**架构级替换**——把大厅 + 所有子游戏迁到 `ylgame://h5/...` 自定义 scheme,由 `AppSchemeHandler`(`WKURLSchemeHandler`)反向映射回沙盒。详见 ADR-010。三条触发动因:① 为未来 Cocos 子游戏 H5 build 适配铺路(file:// 下 Cocos `XHR/fetch` 受 null-origin 限制几乎必踩坑)② 大厅 + 子游戏共用单虚拟 host (`ylgame://h5`) → same-origin → **跨 H5 共享 localStorage**(现状 file:// 下也是同 null-origin 共享,A 方案显式保留此语义)③ 给 `