H5 调 accreditlogin 后 sendAuthReq success=false,根因:微信 OpenSDK
2.0.x 强制 Universal Link,传空串被 SDK 拒绝;daoqi msext 用 1.8.x 不强制
UL,多年稳定上线。沿用 1.8.2 避免无谓的 UL 运维负担(HTTPS 域名 + AASA +
微信开放平台审核 30min-1d)。
文件改动:
- 新增 Vendor/WechatSDK/v1.8.2/{WXApi,WXApiObject,WechatAuthSDK}.h +
libWeChatSDK.a(16MB,fat: i386+armv7+armv7s+x86_64+arm64,从 daoqi
msext/Class/SDKExport/ 直接拷贝)
- 删除 Vendor/WechatSDK/WechatOpenSDK-NoPay.xcframework(2.0.5)
- 新增 ylgamehall/ylgamehall-Bridging-Header.h(1.x .a 无 Swift module,
必须通过 Bridging Header 导入 WXApi.h / WXApiObject.h)
代码侧(5 个 Swift 文件):
- WeChatSDK.swift:register() 改为 1.x 单参数 WXApi.registerApp(appID),
去掉 universalLink 参数;handleOpenURL 不变(1.x/2.x 同款)
- WeChatManager.swift:去掉 #if canImport(WechatOpenSDK) 守卫(Bridging
Header 直接导入,符号编译期必在);authorize sendAuthReq 改 1.x BOOL
返回(无 completion);shareLink/shareImage 改 WXApi.sendReq(req)
(1.x BOOL 返回,无 completion);getVersion → getApiVersion
- AccreditLoginHandler / WechatShare:同样去掉 canImport 守卫和 stub 分支
- BackGameDataHandler:更新注释说明 1.x WXApi delegate 由 sendAuthReq
逐次传入,WeChatManager singleton 持有不需要清理(1.x 早期 setDelegate:
API 已废弃)
文档:
- Vendor/WechatSDK/README.md 重写,说明 1.8.2 决策原因 + 文件结构 +
Xcode 接入 5 步 + M Mac simulator 已知限制
- docs/SDK-Integration-Guide.md §A.1 同步重写
⚠️ **本 commit 后 BuildProject 会失败**,需要用户在 Xcode UI 完成 5 步:
1. 删 Frameworks 里旧 WechatOpenSDK-NoPay.xcframework 引用
2. Add Vendor/WechatSDK/v1.8.2/libWeChatSDK.a(Do Not Embed)
3. Add 4 个系统库:libz.tbd / libsqlite3.tbd / Security.framework /
CFNetwork.framework(Do Not Embed)
4. Build Settings → Header Search Paths += $(PROJECT_DIR)/Vendor/WechatSDK/v1.8.2
5. Build Settings → Objective-C Bridging Header = ylgamehall/ylgamehall-Bridging-Header.h
详细操作步骤见 Vendor/WechatSDK/README.md「Xcode 接入步骤」。
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
81 lines
3.0 KiB
Swift
81 lines
3.0 KiB
Swift
//
|
||
// WechatShare.swift
|
||
// ylgamehall
|
||
//
|
||
// 微信分享 SharePlatform 实现。
|
||
//
|
||
// ⚠️ canImport(WechatOpenSDK) 守卫:SDK 未链接前 isInstalled = true / share = .success
|
||
// 让 SharePanel 按钮可点;项目方在 Xcode Embed & Sign 后真实路径激活。
|
||
//
|
||
|
||
import Foundation
|
||
import UIKit
|
||
|
||
// 微信 SDK 1.8.2 通过 Bridging Header 导入,无 import 语句
|
||
|
||
@MainActor
|
||
public final class WechatShare: SharePlatform {
|
||
|
||
public static let shared = WechatShare()
|
||
|
||
public let name = "WeChat"
|
||
|
||
public var isInstalled: Bool {
|
||
WXApi.isWXAppInstalled()
|
||
}
|
||
|
||
public init() {}
|
||
|
||
public func share(_ content: ShareContent, scene: ShareScene) async -> ShareResult {
|
||
guard WXApi.isWXAppInstalled() else {
|
||
return .notInstalled(platform: name)
|
||
}
|
||
let wxScene: WeChatManager.ShareScene = (scene == .timeline) ? .timeline : .session
|
||
do {
|
||
switch content.type {
|
||
case "1":
|
||
// 链接分享(msext gameController.m:613-635)
|
||
try await WeChatManager.shared.shareLink(
|
||
.init(
|
||
url: content.webpageUrl,
|
||
title: content.title,
|
||
desc: content.desc,
|
||
thumbnailURL: nil
|
||
),
|
||
scene: wxScene
|
||
)
|
||
case "2":
|
||
// 截图分享(msext gameController.m:637-658)
|
||
let shot = try ImageProvider.captureScreenshot()
|
||
guard let imageData = shot.jpegData(compressionQuality: 0.6) else {
|
||
return .failed(reason: "screenshot JPEG encode failed")
|
||
}
|
||
let thumb = ImageProvider.scaledThumb(shot)
|
||
try await WeChatManager.shared.shareImage(
|
||
.init(imageData: imageData, thumb: thumb),
|
||
scene: wxScene
|
||
)
|
||
default:
|
||
// 远端图分享(msext gameController.m:659-680:type 是其它值就当 URL 远端图)
|
||
let remote = try await ImageProvider.downloadRemote(content.webpageUrl)
|
||
// msext 直接用原始 data 作为大图;这里 UIImage 已是 decode 后的,
|
||
// 用 jpegData 重新编码维持等价(避免持有未压缩的原始字节膨胀)。
|
||
guard let imageData = remote.jpegData(compressionQuality: 0.9) else {
|
||
return .failed(reason: "remote image JPEG encode failed")
|
||
}
|
||
let thumb = ImageProvider.scaledThumb(remote)
|
||
try await WeChatManager.shared.shareImage(
|
||
.init(imageData: imageData, thumb: thumb),
|
||
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)")
|
||
}
|
||
}
|
||
}
|