// // WechatShare.swift // ylgamehall // // 微信分享 SharePlatform 实现。 // // ⚠️ canImport(WechatOpenSDK) 守卫:SDK 未链接前 isInstalled = true / share = .success // 让 SharePanel 按钮可点;项目方在 Xcode Embed & Sign 后真实路径激活。 // import Foundation #if canImport(WechatOpenSDK) import WechatOpenSDK #endif @MainActor public final class WechatShare: SharePlatform { public static let shared = WechatShare() public let name = "WeChat" public var isInstalled: Bool { #if canImport(WechatOpenSDK) return WXApi.isWXAppInstalled() #else return true // 未链接 SDK 时让按钮可点,share 也只是 stub success #endif } public init() {} public func share(_ content: ShareContent, scene: ShareScene) async -> ShareResult { #if canImport(WechatOpenSDK) guard WXApi.isWXAppInstalled() else { return .notInstalled(platform: name) } let wxScene: WeChatManager.ShareScene = (scene == .timeline) ? .timeline : .session // 当前仅链接分享(type == "1")走真实 SDK;截图 / 远端图分享待 Phase 4.F 接入 // WXImageObject + WXMediaMessage.thumbData do { try await WeChatManager.shared.shareLink( .init( url: content.webpageUrl, title: content.title, desc: content.desc, thumbnailURL: nil // type=2/3 缩略图待 Phase 4.F ), scene: wxScene ) return .success } catch let WeChatError.shareFailed(errCode) { if errCode == -2 { return .cancelled } return .failed(reason: "WeChat errCode \(errCode)") } catch { return .failed(reason: "\(error)") } #else // SDK 未链接:维持 Phase 4.B 的 stub 行为(让 SharePanel 流程能跑通) return .success #endif } }