Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复iOS18无法唤起QQ的bug #125

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ios/Classes/UIApplication+Hook.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#import <UIKit/UIKit.h>

@interface UIApplication (Hook)
@end
38 changes: 38 additions & 0 deletions ios/Classes/UIApplication+Hook.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#import "UIApplication+Hook.h"
#import <objc/runtime.h>

@implementation UIApplication (Hook)

+ (void)load {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Class class = [self class];
SEL originalSelector = @selector(openURL:);
SEL swizzledSelector = @selector(g_openURL:);
Method originalMethod = class_getInstanceMethod(class, originalSelector);
Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);
if (originalMethod && swizzledMethod) {
method_exchangeImplementations(originalMethod, swizzledMethod);
NSLog(@"openURL: 方法交换成功!");
} else {
NSLog(@"openURL: 方法交换失败!");
}
});
}

- (BOOL)g_openURL:(NSURL *)url {
NSLog(@"拦截到 openURL: %@", url);
// 注意:由于方法交换,调用 g_openURL: 实际上会调用原 openURL: 实现
// 这里我们调用新版 API
if ([UIApplication.sharedApplication respondsToSelector:@selector(openURL:options:completionHandler:)]) {
[UIApplication.sharedApplication openURL:url options:@{} completionHandler:^(BOOL success) {
NSLog(@"openURL:options:completionHandler: 返回 %d", success);
}];
} else {
// 如果低于 iOS 10,调用原始实现
return [self g_openURL:url]; // 注意:由于方法交换,这里 g_openURL: 实际上是原 openURL:
}
return YES;
}

@end