diff --git a/ylgamehall/AppDelegate.swift b/ylgamehall/AppDelegate.swift index 196bb72..66e60a4 100644 --- a/ylgamehall/AppDelegate.swift +++ b/ylgamehall/AppDelegate.swift @@ -12,6 +12,10 @@ final class AppDelegate: UIResponder, UIApplicationDelegate { didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { application.applicationSupportsShakeToEdit = true + // 微信 SDK 1.8.2 内部仍调已弃用的 -[UIApplication openURL:],iOS 17+ SDK + // 链接的 app 会被系统强制返回 NO。必须在 WXApi.registerApp 之前 swizzle。 + WXOpenURLShim.install() + // Phase 4.E 微信 SDK 启动注册(canImport 守卫:未链接时 no-op) WeChatSDK.register() diff --git a/ylgamehall/Source/SDK/WeChat/WXOpenURLShim.swift b/ylgamehall/Source/SDK/WeChat/WXOpenURLShim.swift new file mode 100644 index 0000000..f25976e --- /dev/null +++ b/ylgamehall/Source/SDK/WeChat/WXOpenURLShim.swift @@ -0,0 +1,49 @@ +// +// 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 { + print("[WXOpenURLShim] ⚠️ openURL: method not found, skip") + 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) + print("[WXOpenURLShim] ✅ swizzled -[UIApplication openURL:] → open(_:options:completionHandler:)") + } +}