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).
蹲个官方回复。
上面方法会返回App 再去拉起 微信,这个有好的解决方案吗
微信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);
}
}
微信SDK没适配,暂时可以hook下解决
- (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);
}
}
微信SDK没适配,暂时可以hook下解决
- (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);
}
}
我是在分享扩展调用 openURL: 必现, (用 xcode16 iOS 18), Xcode 15 build 的包没有问题
老哥,怎么解决的,需要使用 swizzle 黑魔法?