// // WeChatSDK.swift // ylgamehall // // 微信 OpenSDK 1.8.2 启动注册(与 daoqi msext 同款,避免 2.x 强制 // Universal Link 的运维负担:HTTPS 域名 + AASA + 微信开放平台后台审核)。 // // 通过 Bridging Header 导入 ObjC 头(1.x .a 静态库无 Swift module), // 详见 ylgamehall-Bridging-Header.h。 // import Foundation import UIKit @MainActor public enum WeChatSDK { /// 微信 AppID — **唯一来源** 是 Info.plist 的 CFBundleURLTypes 中 /// URLName=`weixin` 节点下 CFBundleURLSchemes 的首个 scheme(这是 iOS /// 系统级 URL Scheme 注册,运行期无法注入,必须在 Info.plist 静态声明)。 /// /// 多渠道分发若需更换 AppID,由 plutil 改 Info.plist 同步即可(同样需要 /// 在微信开放平台后台改后台配置),不需要再改 Swift 源码。 /// /// 配置缺失视为构建配置错误,启动期 preconditionFailure(fail-fast)。 public static let appID: String = { guard let urlTypes = Bundle.main.infoDictionary?["CFBundleURLTypes"] as? [[String: Any]], let weixinType = urlTypes.first(where: { ($0["CFBundleURLName"] as? String) == "weixin" }), let schemes = weixinType["CFBundleURLSchemes"] as? [String], let appID = schemes.first, !appID.isEmpty else { preconditionFailure( "Info.plist 缺少 weixin URL Scheme(CFBundleURLTypes 中 CFBundleURLName=weixin 的 CFBundleURLSchemes 首项即为微信 AppID)" ) } return appID }() /// 启动注册:在 AppDelegate.didFinishLaunchingWithOptions 调用一次。 /// 1.x 单参数 registerApp,不需要 Universal Link。 public static func register() { WXApi.registerApp(appID) } /// SceneDelegate.openURLContexts 转发入口。 public static func handleOpenURL(_ url: URL) -> Bool { WXApi.handleOpen(url, delegate: WeChatManager.shared) } }