4.B 分享按页面 mode 拆分:大厅直发微信 3 分支 / 子游戏 SharePanel

【契约影响】docs/H5-Native-Contract.md §3.1[2]

原 msext 把 friendsSharetypeUrlToptitleDescript 同名 handler 在两个 VC
各注册一份且**行为完全不同**:

- NewRootVC.m(大厅):直发微信,3 type 分支
    type==1 sendLinkURL(sharelogo 缩略图)
    type==2 sendImageData(截图 40% 缩放为 thumb)
    其他    NSData fromURL → sendImageData(公众号二维码场景)
- gameController.m(子游戏,活路径,早 return):
    sharefriend==1 SharePanel 三选一
    其他           WechatShareManager 朋友圈兜底(2 分支:截图/链接)

先前新外壳两个 VC 都注册同一份 handler 走"子游戏"逻辑,导致大厅页:
1. 强行弹 SharePanel 多一步操作
2. 丢失"远端图"分支(公众号二维码被错当链接发)

按页面 mode 拆开:

- FriendsShareHandler 加 Mode { lobby, subGame } 参数
- ShareCenter 拆 dispatchLobby(直发微信)/ dispatchSubGame(SharePanel)
- WechatShare 加 shareLobby() 实现完整 3 type 分支:
    type==1 → shareLink + mediaTagName "游戏下载链接" + appIcon thumb
              (原 msext 用 sharelogo.png,按用户决定 fallback 到 app icon)
    type==2 → shareImage + mediaTagName "游戏截图分享" + 截图 0.4x thumb
              + messageExt = H5 description
    其他    → URLSession 下载 NSData 直发 + 远端图 0.4x thumb
              + mediaTagName/messageExt 固定字面"公众号二维码分享"
- WebContainerViewController 注册 .lobby;SubGameViewController .subGame

附带修 sharefriend 默认值:之前 ?? "1"(弹面板)与原 msext nil→[intValue]
==0→朋友圈微信不一致。改成 ?? "",由 ShareCenter default 分支兜底走
朋友圈微信,与原项目完全等价。
This commit is contained in:
joywayer
2026-06-24 08:19:21 +08:00
parent 68c668a06c
commit 5d4bdc2e29
5 changed files with 125 additions and 28 deletions
@@ -5,13 +5,15 @@
// H5 Native handlerfriendsSharetypeUrlToptitleDescript
// docs/H5-Native-Contract.md §3.1 2 + §3.2 11sharesuccess
//
// msext gameController.m:575-597
// 1. ShareContent
// 2. responseCallback("sharefriend")
// 3. bridge.call("sharesuccess", { success:"2", type:<sharefriend > })
// ****H5 """" SDK
// URL Scheme /
// 4. fire-and-forget ShareCenter.dispatch UI
// ** mode ** msext ViewController
// - `.lobby` NewRootVC.m3 type / /
// - `.subGame` gameController.m SharePanel +
//
// mode
// 1. responseCallback("sharefriend")
// 2. bridge.call("sharesuccess", { success:"2", type:<sharefriend > })
// ****URL Scheme /
// 3. mode fire-and-forget UI
//
// SDK
// - WeChatManager 1.8.2 SDK
@@ -23,7 +25,15 @@ import Foundation
@MainActor
public enum FriendsShareHandler {
public static func register(on bridge: any BridgeProtocol) {
/// mode
public enum Mode: Sendable {
/// H5 WebContainer friendsShare
case lobby
/// H5 SubGame friendsShare SharePanel
case subGame
}
public static func register(on bridge: any BridgeProtocol, mode: Mode) {
// 2friendsSharetypeUrlToptitleDescript
// sharefriend / sharetype / type / webpageUrl / title / description
// cb: "sharefriend"msext 沿
@@ -34,9 +44,10 @@ public enum FriendsShareHandler {
guard let obj = data?.asObject else { return }
let content = ShareContent(
sharefriend: obj["sharefriend"]?.asString ?? "1",
// ShareCenter default msext [nil intValue]==0
sharefriend: obj["sharefriend"]?.asString ?? "",
sharetype: obj["sharetype"]?.asString ?? "",
type: obj["type"]?.asString ?? "1",
type: obj["type"]?.asString ?? "",
webpageUrl: obj["webpageUrl"]?.asString ?? "",
title: obj["title"]?.asString ?? "",
desc: obj["description"]?.asString ?? ""
@@ -53,8 +64,11 @@ public enum FriendsShareHandler {
callback: nil
)
// 3. fire-and-forget UI
ShareCenter.dispatch(content)
// 3. fire-and-forget UI mode
switch mode {
case .lobby: ShareCenter.dispatchLobby(content)
case .subGame: ShareCenter.dispatchSubGame(content)
}
}
}
}