iOS 18 WXApi sendReq 无法唤起微信
Xcode版本:Xcode 16
手机版本:iPhone12真机
系统: iOS18
报错信息:BUG IN CLIENT OF UIKIT: The caller of UIApplication.openURL(_:) needs to migrate to the non-deprecated UIApplication.open(_:options:completionHandler:). Force returning false (NO).
你好,升级一下openSDK版本,更新一下接口试试?
https://developers.weixin.qq.com/doc/oplatform/Mobile_App/Access_Guide/iOS.html
若还有问题看下老接口
- (BOOL)openURL:(NSURL*)url API_DEPRECATED_WITH_REPLACEMENT("openURL:options:completionHandler:", ios(2.0, 10.0)) API_UNAVAILABLE(visionos);
有换成新接口吗?
- (void)openURL:(NSURL*)url options:(NSDictionary<UIApplicationOpenExternalURLOptionsKey, id> *)options completionHandler:(void (^ __nullable)(BOOL success))completion API_AVAILABLE(ios(10.0));
感谢码友
我把Swift版本整理下 供码友参考
func hookOldOpenUrl(tragetCls:AnyClass){
let cls = UIApplication.self
let originalSelector = #selector(UIApplication.openURL(_:))
let swizzledSelector = #selector(g_openURL)
let originalMethod = class_getInstanceMethod(cls, originalSelector)
let swizzledMethod = class_getInstanceMethod(tragetCls, swizzledSelector)
let didAddMethod: Bool = class_addMethod(cls, originalSelector, method_getImplementation(swizzledMethod!), method_getTypeEncoding(swizzledMethod!))
if didAddMethod {
class_replaceMethod(cls, swizzledSelector, method_getImplementation(originalMethod!), method_getTypeEncoding(originalMethod!))
} else {
method_exchangeImplementations(originalMethod!, swizzledMethod!)
}
}
@objc func g_openURL(url:URL)->Bool{
UIApplication.shared.open(url)
return true
}
我也有同样的问题,Xcode 15.3 iOS 18,微信分享正常; Xcode升级到16 后, iOS 18微信分享无法调起;
微信SDK升级到2.0.4后,此问题已解决
微信SDK没适配,暂时可以这样解决
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [AppDelegate hookOldOpenUrl:AppDelegate.class]; } - (BOOL)g_openURL:(NSURL*)url { [UIApplication.sharedApplication openURL:url options:nil completionHandler:nil]; return YES; } + (void)hookOldOpenUrl:(Class)targetCls { Class cls = [UIApplication class]; if (cls) { Method originalMethod =class_getInstanceMethod(cls, @selector(openURL:)); Method swizzledMethod =class_getInstanceMethod(targetCls, @selector(g_openURL:)); if (!originalMethod || !swizzledMethod) { return; } IMP originalIMP = method_getImplementation(originalMethod); IMP swizzledIMP = method_getImplementation(swizzledMethod); const char *originalType = method_getTypeEncoding(originalMethod); const char *swizzledType = method_getTypeEncoding(swizzledMethod); class_replaceMethod(cls,@selector(openURL:),swizzledIMP,swizzledType); class_replaceMethod(cls,@selector(g_openURL:),originalIMP,originalType); }}
复现不了无法唤起的情况,苹果iOS18的发布文档确实提到了这个问题(125695759 )。
先hook试试看了
你好,我是用的xcode16和iOS18,然后不管是使用sdk2.0.4,还是上面老哥的重置方法,首次打开app调用检测微信isWXAppInstalled是否存在,都会往微信调一下,然后回来,你们有遇到吗。
- (BOOL)openURL:(NSURL*)url API_DEPRECATED_WITH_REPLACEMENT("openURL:options:completionHandler:", ios(2.0, 10.0)) API_UNAVAILABLE(visionos);
有换成新接口吗?
- (void)openURL:(NSURL*)url options:(NSDictionary<UIApplicationOpenExternalURLOptionsKey, id> *)options completionHandler:(void (^ __nullable)(BOOL success))completion API_AVAILABLE(ios(10.0));
- (BOOL)openURL:(NSURL*)url API_DEPRECATED_WITH_REPLACEMENT("openURL:options:completionHandler:", ios(2.0, 10.0)) API_UNAVAILABLE(visionos);
有换成新接口吗?
- (void)openURL:(NSURL*)url options:(NSDictionary<UIApplicationOpenExternalURLOptionsKey, id> *)options completionHandler:(void (^ __nullable)(BOOL success))completion API_AVAILABLE(ios(10.0));
蹲个官方回复。
上面方法会返回App 再去拉起 微信,这个有好的解决方案吗
我是在分享扩展调用 openURL: 必现, (用 xcode16 iOS 18), Xcode 15 build 的包没有问题
老哥,怎么解决的,需要使用 swizzle 黑魔法?