- AppCoordinator 扩 OverlayRequest + lastOverlayAt(3s 节流 / 栈深 < 3 守门) +
showOverlay / popOverlay(data==nil 仅 pop 即 finishweb 路径;
data!=nil 同时发 .subGameDidReturn 即 backgameData 路径)
- 新增 Source/WebView/OverlayViewController.swift:独立 WKWebView,
WKWebViewConfiguration.websiteDataStore = .nonPersistent() 隔离 Cookie / 缓存;
.atDocumentEnd 注入 polyfill:window.settings = {browser/finishweb/backgameData}
→ webkit.messageHandlers.<name>(与 WVJB 不同 channel 可同名共存);
ScriptMessageProxy weak target 切断 retain cycle
- OpenurlTitleDataHandler 升级为真实 push:解 url / "title "(末尾空格契约)/
data / orientation → AppCoordinator.showOverlay,cb 字面始终回 "OpenurlTitleData"
- SubGameViewController.setupExternalSubscriptions 也订阅 .subGameDidReturn
(overlay 可从子游戏 push,pop 回子游戏时需要 callback 子游戏 H5 的 getWebdata;
与 viewWillAppear/Disappear 生命周期对齐,栈顶才挂钩避免双发)
- orientation 字段保留契约但 landscape-only app 暂不实施旋转(msext 旋转 transform
在我们项目里无意义,记注释,如有 H5 反馈再补)
- Plan §5.7.1-7.7 / §8 进度已勾选
至此 SwitchOverGameData → push 子游戏 / OpenurlTitleData → push 弹层 / backgameData ↔
finishweb → pop + getWebdata 反向闭环全部接通。栈深永远 ≤ 3。
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
49 lines
2.1 KiB
Swift
49 lines
2.1 KiB
Swift
//
|
||
// OpenurlTitleDataHandler.swift
|
||
// ylgamehall
|
||
//
|
||
// H5 → Native handler:OpenurlTitleData — 打开内嵌 WebView 弹层(msext threeView 等价)。
|
||
// 契约:docs/H5-Native-Contract.md §3.1 [15]
|
||
//
|
||
// ⚠️ 入参 key "title " 末尾有空格(msext 历史契约硬约束):
|
||
// 必须 `data["title "]?.asString` 而不是 `data["title"]?.asString`,
|
||
// H5 端 callHandler 时也是 `{"title ": "..."}`(带空格的字符串字面)
|
||
//
|
||
// 与 msext NewRootVC.m / gameController.m 等价:
|
||
// - 大厅 + 子游戏页都注册(msext 两处都有),用户在哪一页调都能打开弹层
|
||
// - 3 秒节流由 AppCoordinator.showOverlay 守门(msext first_Time 等价)
|
||
// - callback 字面始终回 "OpenurlTitleData",无论节流是否命中(msext 行为)
|
||
//
|
||
|
||
import Foundation
|
||
|
||
public enum OpenurlTitleDataHandler {
|
||
|
||
public static func register(on bridge: any BridgeProtocol) {
|
||
// 【15】OpenurlTitleData
|
||
// 入参 url / "title "(末尾空格!) / data / orientation
|
||
// cb: "OpenurlTitleData"
|
||
bridge.register("OpenurlTitleData") { data, callback in
|
||
await MainActor.run {
|
||
// ⚠️ "title " 末尾空格不可改;orientation 在 landscape-only app 中保留契约字段
|
||
let url = data?["url"]?.asString ?? ""
|
||
let title = data?["title "]?.asString ?? ""
|
||
let webData = data?["data"]?.asString ?? ""
|
||
let orientation = data?["orientation"]?.asInt
|
||
?? Int(data?["orientation"]?.asString ?? "")
|
||
?? 0
|
||
|
||
let request = OverlayRequest(
|
||
url: url,
|
||
title: title,
|
||
webData: webData,
|
||
orientation: orientation
|
||
)
|
||
AppCoordinator.shared.showOverlay(request)
|
||
}
|
||
// msext 行为:无论节流命中 / 入参缺失,都回 cb,避免 H5 等待
|
||
callback?(.string("OpenurlTitleData"))
|
||
}
|
||
}
|
||
}
|