Files
youle_app_ios_v2/ylgamehall/Source/Share/ShareCenter.swift
T
joywayer 5d4bdc2e29 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 分支兜底走
朋友圈微信,与原项目完全等价。
2026-06-24 08:19:21 +08:00

46 lines
1.8 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//
// ShareCenter.swift
// ylgamehall
//
// H5 friendsShare 调用入口的协调中心。原 msext 同名 handler 在两个
// ViewController 各注册一份且**行为不同**,新外壳按页面 mode 分发:
//
// • dispatchSubGame — 对齐 msext gameController.m:575-597(活路径):
// - sharefriend == "1" → SharePanel 三选一(微信/QQ/抖音)
// - 其他 → WechatShare.share() 朋友圈 timeline
//
// • dispatchLobby — 对齐 msext NewRootVC.m:453-537:直发微信,无 SharePanel
// - sharefriend == "1" → WXSceneSession(好友)
// - 其他 → WXSceneTimeline(朋友圈)
// - type 3 分支由 WechatShare.shareLobby 内部处理
//
// fire-and-forgetH5 端 sharesuccess 已在 FriendsShareHandler 立即触发,
// 这里只负责拉起 UI / SDK,不需要回传结果。
//
import Foundation
@MainActor
public enum ShareCenter {
/// 子游戏页(SubGameViewController)路径:SharePanel + 朋友圈兜底
public static func dispatchSubGame(_ content: ShareContent) {
switch content.sharefriend {
case "1":
// 好友/私聊 → SharePanel 三选一
SharePanel.show(content: content)
default:
// sharefriend == "2" 或缺失或其他 → msext WechatShareManager
// 内部 [sharefriend intValue] != 1 → WXSceneTimeline 兜底
WechatShare.shared.share(content, scene: .timeline)
}
}
/// 大厅页(WebContainerViewController)路径:直发微信,无 SharePanel
public static func dispatchLobby(_ content: ShareContent) {
let scene: ShareScene = content.sharefriend == "1" ? .friend : .timeline
WechatShare.shared.shareLobby(content, scene: scene)
}
}