Phase 6 commit C:backgameData pop + getWebdata 反向 callback
- 新增 Source/Bridge/Handlers/BackGameDataHandler.swift(仅 SubGameViewController 注册):
- 调 AudioPlayer.stopAllBackground 停背景音
- AppCoordinator.popSubGame(returningData:) → popViewController + 发 .subGameDidReturn
- data 兼容 string / object(非字符串走 JSONSerialization 序列化透传)
- 字面 cb "backgameData"(msext gameController.m:691-709 等价,
WXApi 清理跳过 — 微信 SDK 待 Phase 4.E)
- AudioPlayer.stopAllBackground:无条件停背景音(msext 不看 type 直接 nil 行为)
- SubGameViewController.registerBridgeHandlers:挂上 BackGameDataHandler,
注释更新 exitRoom/getVideoinfo/createRoom 推迟到 Phase 8
- WebContainerViewController:在 setupExternalSubscriptions 挂 .subGameDidReturn
观察者 → bridge.call("getWebdata", .string(data)),teardown 时 removeObserver
(生命周期与 battery/network/appservice 同一对,子游戏栈顶时大厅已 teardown
避免双发)
- Plan §5.6.3 / 6.5 / 6.6 / §8 进度已勾选
至此 SwitchOverGameData → push 子游戏 → backgameData → pop + getWebdata
完整链路接通;子游戏视频房间(exitRoom/getVideoinfo/createRoom)留待 Phase 8。
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
a9eaf86c63
commit
5f3a435180
@@ -21,6 +21,10 @@ public final class WebContainerViewController: UIViewController {
|
||||
|
||||
private let shakeHandler = ShakeHandler()
|
||||
|
||||
// MARK: - .subGameDidReturn 观察者(子游戏 backgameData pop 后回大厅,反向 callback getWebdata)
|
||||
|
||||
private var subGameReturnObserver: NSObjectProtocol?
|
||||
|
||||
// MARK: - Boot pipeline 内部错误分类
|
||||
//
|
||||
// 用 enum 区分"终态阻塞"与"系统级错误":
|
||||
@@ -307,6 +311,21 @@ public final class WebContainerViewController: UIViewController {
|
||||
AppLifecycleObserver.shared.onForeground = {
|
||||
bridge.call("appservice", data: .string("2"), callback: nil)
|
||||
}
|
||||
|
||||
// §3.2 [12] getWebdata — 子游戏 pop 回大厅,反向把 backgameData 入参透传给 H5
|
||||
// (msext NewRootVC 监听 "backgameDatatwo" 通知 → callHandler:"getWebdata" 等价)
|
||||
// 大厅栈顶时挂钩,pop 进子游戏时由 viewWillDisappear teardown 解绑,避免双发。
|
||||
subGameReturnObserver = NotificationCenter.default.addObserver(
|
||||
forName: .subGameDidReturn,
|
||||
object: nil,
|
||||
queue: .main
|
||||
) { note in
|
||||
// queue=.main 保证 closure 在主线程;显式 hop 让 Swift 6 actor 推断通过
|
||||
let data = (note.userInfo?["data"] as? String) ?? ""
|
||||
MainActor.assumeIsolated {
|
||||
bridge.call("getWebdata", data: .string(data), callback: nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func teardownExternalSubscriptions() {
|
||||
@@ -319,6 +338,11 @@ public final class WebContainerViewController: UIViewController {
|
||||
NetworkMonitor.shared.onChange = nil
|
||||
AppLifecycleObserver.shared.onBackground = nil
|
||||
AppLifecycleObserver.shared.onForeground = nil
|
||||
|
||||
if let token = subGameReturnObserver {
|
||||
NotificationCenter.default.removeObserver(token)
|
||||
subGameReturnObserver = nil
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Alerts (terminal / retry states)
|
||||
|
||||
Reference in New Issue
Block a user