处理ios18从其他app用自己键盘 拉起主app的bug
其他问题
This commit is contained in:
52
Shared/KBHostAppLauncher.m
Normal file
52
Shared/KBHostAppLauncher.m
Normal file
@@ -0,0 +1,52 @@
|
||||
//
|
||||
// KBHostAppLauncher.m
|
||||
// keyBoard
|
||||
//
|
||||
// Created by Mac on 2025/11/24.
|
||||
//
|
||||
|
||||
// KBHostAppLauncher.m
|
||||
#import "KBHostAppLauncher.h"
|
||||
#import <objc/message.h>
|
||||
|
||||
@implementation KBHostAppLauncher
|
||||
|
||||
+ (BOOL)openHostAppURL:(NSURL *)url fromResponder:(UIResponder *)startResponder {
|
||||
if (!url || !startResponder) return NO;
|
||||
|
||||
UIResponder *responder = startResponder;
|
||||
while (responder) {
|
||||
if ([responder isKindOfClass:[UIApplication class]]) {
|
||||
UIApplication *app = (UIApplication *)responder;
|
||||
|
||||
if (@available(iOS 18.0, *)) {
|
||||
// iOS 18+:用新的 open:options:completionHandler:
|
||||
SEL sel = @selector(openURL:options:completionHandler:);
|
||||
if ([app respondsToSelector:sel]) {
|
||||
// 等价于 [app openURL:url options:@{} completionHandler:nil];
|
||||
void (*func)(id, SEL, NSURL *, NSDictionary *, void(^)(BOOL)) = (void *)objc_msgSend;
|
||||
if (func) {
|
||||
func(app, sel, url, @{}, nil);
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
return NO;
|
||||
} else {
|
||||
// iOS 17-:兼容老的 openURL:
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
if ([app respondsToSelector:@selector(openURL:)]) {
|
||||
return [app openURL:url];
|
||||
}
|
||||
#pragma clang diagnostic pop
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
responder = responder.nextResponder;
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user