Files
youle_app_ios_v2/ylgamehall/Source/SDK/WeChat/WXOpenURLShim.swift
T
joywayerandClaude Opus 4.7 053232ed26 微信授权链路诊断 print 清理
授权链路已跑通(commit 625f504),撤掉 a060f29 加的临时诊断 print
+ 本次 shim 的 install 成功日志。AccreditLoginHandler / WeChatManager /
WXOpenURLShim 三处共 13 行 print 一次性清干净,行为不变。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-23 17:24:59 +08:00

46 lines
1.7 KiB
Swift

//
// WXOpenURLShim.swift
// ylgamehall
//
// 微信 OpenSDK 1.8.2 内部仍调已弃用的同步 `-[UIApplication openURL:]`。
// 当 app 链接 iOS 17+ SDK(本项目用 Xcode 26 + iOS 26 SDK),系统会把这个
// 老 API 短路、强制返回 NO 不实际拉起任何 URL Scheme。WXApi 据此判定
// sendAuthReq / sendReq 失败,H5 收到 authStepFailed(-3)。
//
// daoqi/msext 同样用 1.8.2 但仍然工作,是因为它的 IPA 用旧 Xcode 链接,
// 系统按"链接时 SDK 版本"放行老 API。本项目无法走那条路。
//
// 方案 A(与项目方确认):保留 1.8.2 + UL 回避策略,仅 swizzle 这一个老
// selector,把调用转发到 `open(_:options:completionHandler:)` 并同步返回
// true(微信已安装时 WXApi 走完后续;外层逻辑早调过 isWXAppInstalled 兜底)。
//
// 作用域:仅替换 UIApplication 实例方法 `openURL:` 的 IMP,不影响其它
// 调用方与新 API。1.8.2 SDK 本身行为不变。
//
import Foundation
import UIKit
import ObjectiveC.runtime
@MainActor
public enum WXOpenURLShim {
private static var installed = false
/// 在 `WXApi.registerApp` 之前调用一次。重复调用 no-op。
public static func install() {
guard !installed else { return }
installed = true
let sel = NSSelectorFromString("openURL:")
guard let method = class_getInstanceMethod(UIApplication.self, sel) else { return }
let block: @convention(block) (UIApplication, URL) -> Bool = { app, url in
app.open(url, options: [:], completionHandler: nil)
return true
}
let imp = imp_implementationWithBlock(block as Any)
method_setImplementation(method, imp)
}
}