41 lines
977 B
Objective-C
41 lines
977 B
Objective-C
//
|
|
// KBHostAppLauncher.m
|
|
// keyBoard
|
|
//
|
|
// Created by Mac on 2025/11/24.
|
|
//
|
|
|
|
// KBHostAppLauncher.m
|
|
#import "KBHostAppLauncher.h"
|
|
#import <TargetConditionals.h>
|
|
#if !TARGET_OS_EXTENSION
|
|
#import <UIKit/UIKit.h>
|
|
#endif
|
|
|
|
@implementation KBHostAppLauncher
|
|
|
|
+ (BOOL)openHostAppURL:(NSURL *)url fromResponder:(UIResponder *)startResponder {
|
|
if (!url || !startResponder) return NO;
|
|
|
|
#if TARGET_OS_EXTENSION
|
|
// App Extension 环境下禁止使用 UIApplication。
|
|
return NO;
|
|
#else
|
|
// 在主 App 内直接通过 UIApplication 打开即可,不需要 responder 链绕行。
|
|
UIApplication *app = UIApplication.sharedApplication;
|
|
if (!app) { return NO; }
|
|
|
|
if (@available(iOS 10.0, *)) {
|
|
[app openURL:url options:@{} completionHandler:nil];
|
|
return YES;
|
|
} else {
|
|
#pragma clang diagnostic push
|
|
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
|
return [app openURL:url];
|
|
#pragma clang diagnostic pop
|
|
}
|
|
#endif
|
|
}
|
|
|
|
@end
|