Phase 4.F:微信截图分享 type=2 / 远端图分享 type=其它
按 msext gameController.m:637-678 字面行为,WechatShare 按 content.type 分发: - type=1 → shareLink(已有) - type=2 → captureScreenshot → JPEG 0.6 + thumb 0.4x → shareImage - type=其它 → downloadRemote(URL) → JPEG 0.9 + thumb 0.4x → shareImage 新增: - ImageProvider.scaledThumb(_:scale:):等价 msext FuncPublic imageByScalingAndCroppingForSize 0.4x 缩放;微信 SDK setThumbImage: 内部再压到 32KB - WeChatManager.ShareImage 结构 + shareImage(_:scene:) 异步包装 (WXImageObject + WXMediaMessage.setThumbImage,FIFO 串行复用 sharePending) 契约:与 type=1 一致,调成功 → sharesuccess 反向 callback(success/cancelled 都发);errCode=-2 → cancelled;其它 errCode → failed。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
d9d9554d9f
commit
8e4c36d1c8
@@ -69,6 +69,19 @@ public final class WeChatManager: NSObject {
|
||||
}
|
||||
}
|
||||
|
||||
/// 图片分享载荷(type=2 截图 / type=3 远端图)。
|
||||
/// imageData 是大图原始字节(JPEG 等),thumb 是缩略图源 — SDK
|
||||
/// `setThumbImage:` 内部把 thumb 压到 32KB。
|
||||
public struct ShareImage {
|
||||
public let imageData: Data
|
||||
public let thumb: UIImage
|
||||
|
||||
public init(imageData: Data, thumb: UIImage) {
|
||||
self.imageData = imageData
|
||||
self.thumb = thumb
|
||||
}
|
||||
}
|
||||
|
||||
/// 链接分享(FIFO 串行)。微信回包不携带配对 ID,连续调时按入队顺序消费。
|
||||
public func shareLink(_ link: ShareLink, scene: ShareScene) async throws {
|
||||
#if canImport(WechatOpenSDK)
|
||||
@@ -97,6 +110,35 @@ public final class WeChatManager: NSObject {
|
||||
#endif
|
||||
}
|
||||
|
||||
/// 图片分享(FIFO 串行,复用 sharePending)。msext gameController.m:637-678
|
||||
/// type=2 截图 / type=其它 远端图 共用同一条 WXImageObject + setThumbImage 路径。
|
||||
public func shareImage(_ img: ShareImage, scene: ShareScene) async throws {
|
||||
#if canImport(WechatOpenSDK)
|
||||
try await withCheckedThrowingContinuation { (cont: CheckedContinuation<Void, Error>) in
|
||||
sharePending.append(cont)
|
||||
|
||||
let media = WXImageObject()
|
||||
media.imageData = img.imageData
|
||||
|
||||
let message = WXMediaMessage()
|
||||
// 图片分享不需要 title / description(msext 字面:传 nil;这里传空串等价)
|
||||
message.mediaObject = media
|
||||
message.setThumbImage(img.thumb)
|
||||
|
||||
let req = SendMessageToWXReq()
|
||||
req.bText = false
|
||||
req.message = message
|
||||
switch scene {
|
||||
case .session: req.scene = Int32(WXSceneSession.rawValue)
|
||||
case .timeline: req.scene = Int32(WXSceneTimeline.rawValue)
|
||||
}
|
||||
WXApi.send(req)
|
||||
}
|
||||
#else
|
||||
throw WeChatError.sdkNotLinked
|
||||
#endif
|
||||
}
|
||||
|
||||
// MARK: - Internal: resolve callbacks
|
||||
|
||||
fileprivate func resolveAuth(state: String, code: String?, errCode: Int) {
|
||||
|
||||
Reference in New Issue
Block a user