微信 1.8.2 兼容 iOS 17+ SDK:swizzle 弃用的 openURL: 转发到新 API
WeChat OpenSDK 1.8.2 内部仍调 -[UIApplication openURL:],本项目链接 iOS 26 SDK 时被系统强制返回 NO("BUG IN CLIENT OF UIKIT ... Force returning false"),导致 WXApi.sendAuthReq / sendReq 一律失败、H5 拿到 authStepFailed(-3)。 WXOpenURLShim 用 method_setImplementation 把这一个 selector 的 IMP 替换为转发到 open(_:options:completionHandler:) 并同步返回 true, 作用域仅限此老 API。在 WXApi.registerApp 之前 install 一次。 daoqi/msext 用 1.8.2 没此问题,是因为它 IPA 链接的 base SDK 更低、 系统对老 app 放行 openURL:。新外壳无此豁免,需要这层兜底。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
f6142ced41
commit
625f504b85
@@ -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:)")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user