微信 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:
joywayer
2026-06-23 17:22:17 +08:00
co-authored by Claude Opus 4.7
parent f6142ced41
commit 625f504b85
2 changed files with 53 additions and 0 deletions
+4
View File
@@ -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()
@@ -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 SchemeWXApi
// 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
// API1.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:)")
}
}