Phase 1.F: WebView 加载从 file:// 迁到 ylgame://h5 自定义 scheme
为未来 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 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
960adc5491
commit
04e702a99b
@@ -30,6 +30,18 @@ public final class BridgedWebView: UIView {
|
||||
configuration.mediaTypesRequiringUserActionForPlayback = []
|
||||
configuration.processPool = SharedProcessPool.shared
|
||||
|
||||
// ── 自定义 URL scheme 注册(Phase 1.F)────────────────────
|
||||
// 大厅 + 子游戏的 H5 通过 `ylgame://h5/...` 加载,由 AppSchemeHandler 反向
|
||||
// 映射到沙盒文件。理由(详见 docs/H5-Native-Implementation-Design.md §17):
|
||||
// - file:// origin 是 null,XHR/fetch 受限;自定义 scheme 是稳定 origin
|
||||
// - 大厅 + 所有子游戏共用 `ylgame://h5` 单 host → same-origin →
|
||||
// 共享 localStorage(与现状 file:// 等价)
|
||||
// - 为未来 Cocos 子游戏 H5 适配铺路
|
||||
configuration.setURLSchemeHandler(
|
||||
AppSchemeHandler.shared,
|
||||
forURLScheme: AppScheme.scheme
|
||||
)
|
||||
|
||||
// ── 在 documentStart 注入 WebViewJavascriptBridge.js ─────
|
||||
// .atDocumentStart 保证 H5 业务代码运行时 window.WebViewJavascriptBridge 已就绪
|
||||
if let url = Bundle.main.url(forResource: "WebViewJavascriptBridge",
|
||||
|
||||
Reference in New Issue
Block a user