53 lines
1.6 KiB
Mathematica
53 lines
1.6 KiB
Mathematica
|
|
//
|
|||
|
|
// 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
|
|||
|
|
|