From fc87c545a0312b40e3467cddfe15614efa817f6a Mon Sep 17 00:00:00 2001 From: CodeST <694468528@qq.com> Date: Fri, 21 Nov 2025 18:26:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=81=E8=A3=85=E8=B7=A8=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E6=8B=89=E8=B5=B7=EF=BC=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CustomKeyboard/KeyboardViewController.m | 23 ++- CustomKeyboard/Utils/KBExtensionAppLauncher.h | 36 +++++ CustomKeyboard/Utils/KBExtensionAppLauncher.m | 121 ++++++++++++++++ CustomKeyboard/Utils/KBURLOpenBridge.h | 30 ---- CustomKeyboard/Utils/KBURLOpenBridge.m | 46 ------ CustomKeyboard/View/KBFullAccessGuideView.m | 69 ++------- CustomKeyboard/View/KBFunctionView.m | 54 +++---- ...{KBULBridge.h => KBULBridgeNotification.h} | 2 +- ...{KBULBridge.m => KBULBridgeNotification.m} | 4 +- keyBoard.xcodeproj/project.pbxproj | 28 ++-- keyBoard/AppDelegate.m | 133 ++++-------------- 11 files changed, 251 insertions(+), 295 deletions(-) create mode 100644 CustomKeyboard/Utils/KBExtensionAppLauncher.h create mode 100644 CustomKeyboard/Utils/KBExtensionAppLauncher.m delete mode 100644 CustomKeyboard/Utils/KBURLOpenBridge.h delete mode 100644 CustomKeyboard/Utils/KBURLOpenBridge.m rename Shared/{KBULBridge.h => KBULBridgeNotification.h} (94%) rename Shared/{KBULBridge.m => KBULBridgeNotification.m} (66%) diff --git a/CustomKeyboard/KeyboardViewController.m b/CustomKeyboard/KeyboardViewController.m index 2adb859..584cb56 100644 --- a/CustomKeyboard/KeyboardViewController.m +++ b/CustomKeyboard/KeyboardViewController.m @@ -16,6 +16,7 @@ #import "KBFullAccessManager.h" #import "KBSkinManager.h" #import "KBSkinInstallBridge.h" +#import "KBExtensionAppLauncher.h" // 提前声明一个类别,使编译器在 static 回调中识别 kb_consumePendingShopSkin 方法。 @interface KeyboardViewController (KBSkinShopBridge) @@ -206,13 +207,25 @@ static void KBSkinInstallNotificationCallback(CFNotificationCenterRef center, } - (void)keyBoardMainView:(KBKeyBoardMainView *)keyBoardMainView didTapToolActionAtIndex:(NSInteger)index { - if (index == 0) { - /// 充值操作 - [KBHUD showInfo:KBLocalized(@"Recharge Now")]; -// [self showFunctionPanel:YES]; - } else { + if (index != 0) { [self showFunctionPanel:NO]; + return; } + + // 1. 构造自定义 scheme:kbkeyboardAppExtension://recharge?src=keyboard + NSString *urlStr = [NSString stringWithFormat:@"%@://recharge?src=keyboard", KB_APP_SCHEME]; + NSURL *scheme = [NSURL URLWithString:urlStr]; + if (!scheme) return; + + // 2. 通过统一工具封装:extensionContext + 响应链兜底 + [KBExtensionAppLauncher openScheme:scheme + usingInputController:self + source:self.view + completion:^(BOOL success) { + if (!success) { + [KBHUD showInfo:KBLocalized(@"请切换到主App完成充值")]; + } + }]; } - (void)keyBoardMainViewDidTapSettings:(KBKeyBoardMainView *)keyBoardMainView { diff --git a/CustomKeyboard/Utils/KBExtensionAppLauncher.h b/CustomKeyboard/Utils/KBExtensionAppLauncher.h new file mode 100644 index 0000000..14eb394 --- /dev/null +++ b/CustomKeyboard/Utils/KBExtensionAppLauncher.h @@ -0,0 +1,36 @@ +// +// KBExtensionAppLauncher.h +// CustomKeyboard +// +// 封装:在键盘扩展中拉起主 App(Scheme / Universal Link + 响应链兜底)。 +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface KBExtensionAppLauncher : NSObject + +/// 通用入口:优先尝试 primaryURL,失败后尝试 fallbackURL, +/// 两者都失败时再通过响应链(openURL:)做兜底。 +/// - Parameters: +/// - primaryURL: 第一优先尝试的 URL(可为 Scheme 或 UL) +/// - fallbackURL: 失败时的备用 URL(可为 nil) +/// - ivc: 当前的 UIInputViewController(用于 extensionContext openURL) +/// - source: 兜底时用作起点的 responder(通常传 self 或 self.view) +/// - completion: 最终是否“看起来已成功发起”打开动作(不保证一定跳转到 App) ++ (void)openPrimaryURL:(NSURL * _Nullable)primaryURL + fallbackURL:(NSURL * _Nullable)fallbackURL + usingInputController:(UIInputViewController *)ivc + source:(UIResponder *)source + completion:(void (^ _Nullable)(BOOL success))completion; + +/// 简化版:只针对单一 Scheme 做尝试 + 响应链兜底。 ++ (void)openScheme:(NSURL *)scheme + usingInputController:(UIInputViewController *)ivc + source:(UIResponder *)source + completion:(void (^ _Nullable)(BOOL success))completion; + +@end + +NS_ASSUME_NONNULL_END diff --git a/CustomKeyboard/Utils/KBExtensionAppLauncher.m b/CustomKeyboard/Utils/KBExtensionAppLauncher.m new file mode 100644 index 0000000..f4b1e00 --- /dev/null +++ b/CustomKeyboard/Utils/KBExtensionAppLauncher.m @@ -0,0 +1,121 @@ +// +// KBExtensionAppLauncher.m +// CustomKeyboard +// + +#import "KBExtensionAppLauncher.h" +#import + +@implementation KBExtensionAppLauncher + ++ (void)openPrimaryURL:(NSURL * _Nullable)primaryURL + fallbackURL:(NSURL * _Nullable)fallbackURL + usingInputController:(UIInputViewController *)ivc + source:(UIResponder *)source + completion:(void (^ _Nullable)(BOOL success))completion { + if (!ivc || (!primaryURL && !fallbackURL)) { + if (completion) { completion(NO); } + return; + } + + // 保证在主线程回调,避免调用方再做一次 dispatch。 + void (^finish)(BOOL) = ^(BOOL ok){ + if (!completion) return; + if ([NSThread isMainThread]) { + completion(ok); + } else { + dispatch_async(dispatch_get_main_queue(), ^{ completion(ok); }); + } + }; + + NSURL *first = primaryURL ?: fallbackURL; + NSURL *second = (first == primaryURL) ? fallbackURL : nil; + + if (!first) { + finish(NO); + return; + } + + [ivc.extensionContext openURL:first completionHandler:^(BOOL ok) { + if (ok) { + finish(YES); + return; + } + + if (second) { + [ivc.extensionContext openURL:second completionHandler:^(BOOL ok2) { + if (ok2) { + finish(YES); + return; + } + BOOL bridged = [self p_bridgeFirst:first second:second from:source]; + finish(bridged); + }]; + } else { + BOOL bridged = [self p_bridgeFirst:first second:nil from:source]; + finish(bridged); + } + }]; +} + ++ (void)openScheme:(NSURL *)scheme + usingInputController:(UIInputViewController *)ivc + source:(UIResponder *)source + completion:(void (^ _Nullable)(BOOL success))completion { + [self openPrimaryURL:scheme + fallbackURL:nil + usingInputController:ivc + source:source + completion:completion]; +} + +#pragma mark - Private + +// 通过响应链尝试调用 openURL:(等价于原 KBURLOpenBridge 实现) ++ (BOOL)p_openURLViaResponder:(NSURL *)url from:(UIResponder *)start { +#if KB_URL_BRIDGE_ENABLE + if (!url || !start) return NO; + SEL sel = NSSelectorFromString(@"openURL:"); + UIResponder *responder = start; + while (responder) { + @try { + if ([responder respondsToSelector:sel]) { + BOOL handled = NO; + BOOL (*funcBool)(id, SEL, NSURL *) = (BOOL (*)(id, SEL, NSURL *))objc_msgSend; + if (funcBool) { + handled = funcBool(responder, sel, url); + } else { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Warc-performSelector-leaks" + [responder performSelector:sel withObject:url]; + handled = YES; +#pragma clang diagnostic pop + } + return handled; + } + } @catch (__unused NSException *e) { + // ignore and continue + } + responder = responder.nextResponder; + } + return NO; +#else + (void)url; (void)start; + return NO; +#endif +} + ++ (BOOL)p_bridgeFirst:(NSURL * _Nullable)first + second:(NSURL * _Nullable)second + from:(UIResponder *)source { + BOOL bridged = NO; + if (first) { + bridged = [self p_openURLViaResponder:first from:source]; + } + if (!bridged && second) { + bridged = [self p_openURLViaResponder:second from:source]; + } + return bridged; +} + +@end diff --git a/CustomKeyboard/Utils/KBURLOpenBridge.h b/CustomKeyboard/Utils/KBURLOpenBridge.h deleted file mode 100644 index 9237c7b..0000000 --- a/CustomKeyboard/Utils/KBURLOpenBridge.h +++ /dev/null @@ -1,30 +0,0 @@ -// -// KBURLOpenBridge.h -// 非公开:通过响应链查找 `openURL:` 选择器,尝试在扩展环境中打开自定义 scheme。 -// 警告:存在审核风险。默认仅 Debug 启用(见 KB_URL_BRIDGE_ENABLE)。 -// - -#import - -NS_ASSUME_NONNULL_BEGIN - -#ifndef KB_URL_BRIDGE_ENABLE -#if DEBUG -#define KB_URL_BRIDGE_ENABLE 1 -#else -#define KB_URL_BRIDGE_ENABLE 0 -#endif -#endif - -@interface KBURLOpenBridge : NSObject - -/// 尝试通过响应链调用 openURL:(仅在 KB_URL_BRIDGE_ENABLE 为 1 时执行)。 -/// @param url 自定义 scheme,如 kbkeyboard://settings -/// @param start 起始 responder(传 self 或任意视图) -/// @return 是否看起来已发起打开动作(不保证一定成功) -+ (BOOL)openURLViaResponder:(NSURL *)url from:(UIResponder *)start; - -@end - -NS_ASSUME_NONNULL_END - diff --git a/CustomKeyboard/Utils/KBURLOpenBridge.m b/CustomKeyboard/Utils/KBURLOpenBridge.m deleted file mode 100644 index 84aaaed..0000000 --- a/CustomKeyboard/Utils/KBURLOpenBridge.m +++ /dev/null @@ -1,46 +0,0 @@ -// -// KBURLOpenBridge.m -// - -#import "KBURLOpenBridge.h" -#import - -@implementation KBURLOpenBridge - -+ (BOOL)openURLViaResponder:(NSURL *)url from:(UIResponder *)start { -#if KB_URL_BRIDGE_ENABLE - if (!url || !start) return NO; - SEL sel = NSSelectorFromString(@"openURL:"); - UIResponder *responder = start; - while (responder) { - @try { - if ([responder respondsToSelector:sel]) { - // 尽量按签名调用;若失败则回退 performSelector - BOOL handled = NO; - // 尝试 (BOOL)openURL:(NSURL *) - BOOL (*funcBool)(id, SEL, NSURL *) = (BOOL (*)(id, SEL, NSURL *))objc_msgSend; - if (funcBool) { - handled = funcBool(responder, sel, url); - } else { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Warc-performSelector-leaks" - [responder performSelector:sel withObject:url]; - handled = YES; -#pragma clang diagnostic pop - } - return handled; - } - } @catch (__unused NSException *e) { - // ignore and continue - } - responder = responder.nextResponder; - } - return NO; -#else - (void)url; (void)start; - return NO; -#endif -} - -@end - diff --git a/CustomKeyboard/View/KBFullAccessGuideView.m b/CustomKeyboard/View/KBFullAccessGuideView.m index 98803f7..571a95f 100644 --- a/CustomKeyboard/View/KBFullAccessGuideView.m +++ b/CustomKeyboard/View/KBFullAccessGuideView.m @@ -7,7 +7,7 @@ #import "Masonry.h" #import "KBResponderUtils.h" // 统一查找 UIInputViewController 的工具 #import "KBHUD.h" -#import "KBURLOpenBridge.h" +#import "KBExtensionAppLauncher.h" @interface KBFullAccessGuideView () @property (nonatomic, strong) UIControl *backdrop; @@ -168,63 +168,20 @@ // Universal Link(需 AASA/Associated Domains 配置且 KB_UL_BASE 与域名一致) NSURL *ul = [NSURL URLWithString:[NSString stringWithFormat:@"%@?src=kb_extension", KB_UL_SETTINGS]]; - void (^finish)(BOOL) = ^(BOOL ok){ - if (ok) { [self dismiss]; } - else { + __weak typeof(self) weakSelf = self; + [KBExtensionAppLauncher openPrimaryURL:scheme + fallbackURL:ul + usingInputController:ivc + source:self + completion:^(BOOL ok) { + __strong typeof(weakSelf) strongSelf = weakSelf; + if (!strongSelf) return; + if (ok) { + [strongSelf dismiss]; + } else { NSString *showInfo = [NSString stringWithFormat:KBLocalized(@"Follow: Settings → General → Keyboard → Keyboards → %@ → Allow Full Access"),AppName]; [KBHUD showInfo:showInfo]; } - }; - - // 先试 Scheme(更可能被宿主允许直接拉起 App) - if (scheme) { - [ivc.extensionContext openURL:scheme completionHandler:^(BOOL ok) { - if (ok) { finish(YES); return; } - if (ul) { - [ivc.extensionContext openURL:ul completionHandler:^(BOOL ok2) { - if (ok2) { finish(YES); return; } - // 兜底:在用户点击触发的场景下,尝试通过响应链调用 openURL: - BOOL bridged = NO; - @try { - #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Wunguarded-availability" - bridged = [KBURLOpenBridge openURLViaResponder:scheme from:self]; - if (!bridged && ul) { - bridged = [KBURLOpenBridge openURLViaResponder:ul from:self]; - } - #pragma clang diagnostic pop - } @catch (__unused NSException *e) { bridged = NO; } - finish(bridged); - }]; - } else { - // 没有 UL,则直接尝试桥接 Scheme - BOOL bridged = NO; - @try { - #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Wunguarded-availability" - bridged = [KBURLOpenBridge openURLViaResponder:scheme from:self]; - #pragma clang diagnostic pop - } @catch (__unused NSException *e) { bridged = NO; } - finish(bridged); - } - }]; - return; - } - // 无 scheme 时,直接尝试 UL - if (ul) { - [ivc.extensionContext openURL:ul completionHandler:^(BOOL ok) { - if (ok) { finish(YES); return; } - BOOL bridged = NO; - @try { - #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Wunguarded-availability" - bridged = [KBURLOpenBridge openURLViaResponder:ul from:self]; - #pragma clang diagnostic pop - } @catch (__unused NSException *e) { bridged = NO; } - finish(bridged); - }]; - } else { - finish(NO); - } + }]; } @end diff --git a/CustomKeyboard/View/KBFunctionView.m b/CustomKeyboard/View/KBFunctionView.m index ee2cc5e..cf9a339 100644 --- a/CustomKeyboard/View/KBFunctionView.m +++ b/CustomKeyboard/View/KBFunctionView.m @@ -16,8 +16,8 @@ #import "KBFullAccessManager.h" #import "KBSkinManager.h" #import "KBAuthManager.h" // 登录态判断(共享钥匙串) -#import "KBULBridge.h" // Darwin 通知常量(UL 已处理) -#import "KBURLOpenBridge.h" // 兜底从扩展侧直接尝试 openURL: +#import "KBULBridgeNotification.h" // Darwin 通知常量(UL 已处理) +#import "KBExtensionAppLauncher.h" #import "KBStreamTextView.h" // 流式文本视图 #import "KBStreamOverlayView.h" // 带关闭按钮的流式层 #import "KBFunctionTagListView.h" @@ -329,16 +329,11 @@ static NSString * const kKBStreamDemoURL = @"http://192.168.1.144:7529/api/demo/ if (self.kb_ulHandledFlag) return; // 主 App 已确认处理 NSURL *scheme = [NSURL URLWithString:[NSString stringWithFormat:@"%@://login?src=functionView&index=%ld&title=%@", KB_APP_SCHEME, (long)index, encodedTitle]]; if (!scheme) return; - [ivc.extensionContext openURL:scheme completionHandler:^(__unused BOOL ok2) { - if (ok2) return; - BOOL bridged = NO; - @try { - #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Wunguarded-availability" - bridged = [KBURLOpenBridge openURLViaResponder:scheme from:self]; - #pragma clang diagnostic pop - } @catch (__unused NSException *e) { bridged = NO; } - if (!bridged) { + [KBExtensionAppLauncher openScheme:scheme + usingInputController:ivc + source:self + completion:^(BOOL success) { + if (!success) { [KBHUD showInfo:KBLocalized(@"请切换到主App完成登录")]; } }]; @@ -383,29 +378,18 @@ static void KBULDarwinCallback(CFNotificationCenterRef center, void *observer, C if (!ul) return; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.05 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - [ivc.extensionContext openURL:ul completionHandler:^(BOOL ok) { - if (ok) return; // Universal Link 成功 - - // 统一使用主 App 注册的自定义 Scheme - NSURL *scheme = [NSURL URLWithString:[NSString stringWithFormat:@"%@@//login?src=functionView&index=%ld&title=%@", KB_APP_SCHEME, (long)indexPath.item, encodedTitle]]; - [ivc.extensionContext openURL:scheme completionHandler:^(BOOL ok2) { - if (ok2) return; - - // 兜底:在用户点击触发的场景下,尝试通过响应链调用 openURL: - // 以提升在“备忘录”等宿主中的成功率。 - BOOL bridged = NO; - @try { - #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Wunguarded-availability" - bridged = [KBURLOpenBridge openURLViaResponder:scheme from:self]; - #pragma clang diagnostic pop - } @catch (__unused NSException *e) { bridged = NO; } - - if (!bridged) { - // 两条路都失败:大概率未开完全访问或宿主拦截。统一交由 Manager 引导。 - dispatch_async(dispatch_get_main_queue(), ^{ [[KBFullAccessManager shared] ensureFullAccessOrGuideInView:self]; }); - } - }]; + NSURL *scheme = [NSURL URLWithString:[NSString stringWithFormat:@"%@@//login?src=functionView&index=%ld&title=%@", KB_APP_SCHEME, (long)indexPath.item, encodedTitle]]; + [KBExtensionAppLauncher openPrimaryURL:ul + fallbackURL:scheme + usingInputController:ivc + source:self + completion:^(BOOL success) { + if (!success) { + // 两条路都失败:大概率未开完全访问或宿主拦截。统一交由 Manager 引导。 + dispatch_async(dispatch_get_main_queue(), ^{ + [[KBFullAccessManager shared] ensureFullAccessOrGuideInView:self]; + }); + } }]; }); } diff --git a/Shared/KBULBridge.h b/Shared/KBULBridgeNotification.h similarity index 94% rename from Shared/KBULBridge.h rename to Shared/KBULBridgeNotification.h index 90f75f5..0d98854 100644 --- a/Shared/KBULBridge.h +++ b/Shared/KBULBridgeNotification.h @@ -1,5 +1,5 @@ // -// KBULBridge.h +// KBULBridgeNotification.h // 通用的 UL/Scheme 拉起桥接常量(App 与键盘扩展共享) // // 用途:主 App 在成功处理 Universal Link(如 /ul/login)时, diff --git a/Shared/KBULBridge.m b/Shared/KBULBridgeNotification.m similarity index 66% rename from Shared/KBULBridge.m rename to Shared/KBULBridgeNotification.m index b64abfc..bf778bb 100644 --- a/Shared/KBULBridge.m +++ b/Shared/KBULBridgeNotification.m @@ -1,8 +1,8 @@ // -// KBULBridge.m +// KBULBridgeNotification.m // -#import "KBULBridge.h" +#import "KBULBridgeNotification.h" /// Darwin 跨进程通知:UL 已被主 App 处理 NSString * const KBDarwinULHandled = @"com.loveKey.nyx.ul.opened"; diff --git a/keyBoard.xcodeproj/project.pbxproj b/keyBoard.xcodeproj/project.pbxproj index 8507fcb..9eb0ef1 100644 --- a/keyBoard.xcodeproj/project.pbxproj +++ b/keyBoard.xcodeproj/project.pbxproj @@ -38,7 +38,7 @@ 0459D1B82EBA287900F2D189 /* KBSkinManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 0459D1B62EBA287900F2D189 /* KBSkinManager.m */; }; 046131112ECF3A6E00A6FADF /* fense.zip in Resources */ = {isa = PBXBuildFile; fileRef = 046131102ECF3A6E00A6FADF /* fense.zip */; }; 046131142ECF454500A6FADF /* KBKeyPreviewView.m in Sources */ = {isa = PBXBuildFile; fileRef = 046131132ECF454500A6FADF /* KBKeyPreviewView.m */; }; - 0477BD952EBAFF4E0055D639 /* KBURLOpenBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = 0477BD932EBAFF4E0055D639 /* KBURLOpenBridge.m */; }; + 046131172ED06FC800A6FADF /* KBExtensionAppLauncher.m in Sources */ = {isa = PBXBuildFile; fileRef = 046131162ED06FC800A6FADF /* KBExtensionAppLauncher.m */; }; 0477BDF02EBB76E30055D639 /* HomeSheetVC.m in Sources */ = {isa = PBXBuildFile; fileRef = 0477BDEF2EBB76E30055D639 /* HomeSheetVC.m */; }; 0477BDF32EBB7B850055D639 /* KBDirectionIndicatorView.m in Sources */ = {isa = PBXBuildFile; fileRef = 0477BDF22EBB7B850055D639 /* KBDirectionIndicatorView.m */; }; 0477BDF72EBC63A80055D639 /* KBTestVC.m in Sources */ = {isa = PBXBuildFile; fileRef = 0477BDF62EBC63A80055D639 /* KBTestVC.m */; }; @@ -93,8 +93,8 @@ 049FB2352EC45C6A00FAB05D /* NetworkStreamHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 049FB2342EC45C6A00FAB05D /* NetworkStreamHandler.m */; }; 049FB23B2EC4766700FAB05D /* KBFunctionTagListView.m in Sources */ = {isa = PBXBuildFile; fileRef = 049FB2372EC4766700FAB05D /* KBFunctionTagListView.m */; }; 049FB23C2EC4766700FAB05D /* KBStreamOverlayView.m in Sources */ = {isa = PBXBuildFile; fileRef = 049FB2392EC4766700FAB05D /* KBStreamOverlayView.m */; }; - 049FB23F2EC4B6EF00FAB05D /* KBULBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = 049FB23E2EC4B6EF00FAB05D /* KBULBridge.m */; }; - 049FB2402EC4B6EF00FAB05D /* KBULBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = 049FB23E2EC4B6EF00FAB05D /* KBULBridge.m */; }; + 049FB23F2EC4B6EF00FAB05D /* KBULBridgeNotification.m in Sources */ = {isa = PBXBuildFile; fileRef = 049FB23E2EC4B6EF00FAB05D /* KBULBridgeNotification.m */; }; + 049FB2402EC4B6EF00FAB05D /* KBULBridgeNotification.m in Sources */ = {isa = PBXBuildFile; fileRef = 049FB23E2EC4B6EF00FAB05D /* KBULBridgeNotification.m */; }; 049FB2432EC4BBB700FAB05D /* KBLoginPopView.m in Sources */ = {isa = PBXBuildFile; fileRef = 049FB2422EC4BBB700FAB05D /* KBLoginPopView.m */; }; 049FB31D2EC21BCD00FAB05D /* KBMyKeyboardCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 049FB31C2EC21BCD00FAB05D /* KBMyKeyboardCell.m */; }; 04A9FE0F2EB481100020DB6D /* KBHUD.m in Sources */ = {isa = PBXBuildFile; fileRef = 04FC97082EB31B14007BD342 /* KBHUD.m */; }; @@ -233,8 +233,8 @@ 046131102ECF3A6E00A6FADF /* fense.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = fense.zip; sourceTree = ""; }; 046131122ECF454500A6FADF /* KBKeyPreviewView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBKeyPreviewView.h; sourceTree = ""; }; 046131132ECF454500A6FADF /* KBKeyPreviewView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KBKeyPreviewView.m; sourceTree = ""; }; - 0477BD922EBAFF4E0055D639 /* KBURLOpenBridge.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBURLOpenBridge.h; sourceTree = ""; }; - 0477BD932EBAFF4E0055D639 /* KBURLOpenBridge.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KBURLOpenBridge.m; sourceTree = ""; }; + 046131152ED06FC800A6FADF /* KBExtensionAppLauncher.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBExtensionAppLauncher.h; sourceTree = ""; }; + 046131162ED06FC800A6FADF /* KBExtensionAppLauncher.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KBExtensionAppLauncher.m; sourceTree = ""; }; 0477BDEE2EBB76E30055D639 /* HomeSheetVC.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HomeSheetVC.h; sourceTree = ""; }; 0477BDEF2EBB76E30055D639 /* HomeSheetVC.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HomeSheetVC.m; sourceTree = ""; }; 0477BDF12EBB7B850055D639 /* KBDirectionIndicatorView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBDirectionIndicatorView.h; sourceTree = ""; }; @@ -345,8 +345,8 @@ 049FB2372EC4766700FAB05D /* KBFunctionTagListView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KBFunctionTagListView.m; sourceTree = ""; }; 049FB2382EC4766700FAB05D /* KBStreamOverlayView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBStreamOverlayView.h; sourceTree = ""; }; 049FB2392EC4766700FAB05D /* KBStreamOverlayView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KBStreamOverlayView.m; sourceTree = ""; }; - 049FB23D2EC4B6EF00FAB05D /* KBULBridge.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBULBridge.h; sourceTree = ""; }; - 049FB23E2EC4B6EF00FAB05D /* KBULBridge.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KBULBridge.m; sourceTree = ""; }; + 049FB23D2EC4B6EF00FAB05D /* KBULBridgeNotification.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBULBridgeNotification.h; sourceTree = ""; }; + 049FB23E2EC4B6EF00FAB05D /* KBULBridgeNotification.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KBULBridgeNotification.m; sourceTree = ""; }; 049FB2412EC4BBB700FAB05D /* KBLoginPopView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBLoginPopView.h; sourceTree = ""; }; 049FB2422EC4BBB700FAB05D /* KBLoginPopView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KBLoginPopView.m; sourceTree = ""; }; 049FB31B2EC21BCD00FAB05D /* KBMyKeyboardCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBMyKeyboardCell.h; sourceTree = ""; }; @@ -587,8 +587,8 @@ 0477BD942EBAFF4E0055D639 /* Utils */ = { isa = PBXGroup; children = ( - 0477BD922EBAFF4E0055D639 /* KBURLOpenBridge.h */, - 0477BD932EBAFF4E0055D639 /* KBURLOpenBridge.m */, + 046131152ED06FC800A6FADF /* KBExtensionAppLauncher.h */, + 046131162ED06FC800A6FADF /* KBExtensionAppLauncher.m */, ); path = Utils; sourceTree = ""; @@ -1272,8 +1272,8 @@ 04A9FE192EB892460020DB6D /* KBLocalizationManager.m */, 0459D1B52EBA287900F2D189 /* KBSkinManager.h */, 0459D1B62EBA287900F2D189 /* KBSkinManager.m */, - 049FB23D2EC4B6EF00FAB05D /* KBULBridge.h */, - 049FB23E2EC4B6EF00FAB05D /* KBULBridge.m */, + 049FB23D2EC4B6EF00FAB05D /* KBULBridgeNotification.h */, + 049FB23E2EC4B6EF00FAB05D /* KBULBridgeNotification.m */, 04D1F6B02EDFF10A00B12345 /* KBSkinInstallBridge.h */, 04D1F6B12EDFF10A00B12345 /* KBSkinInstallBridge.m */, ); @@ -1540,11 +1540,12 @@ 049FB2352EC45C6A00FAB05D /* NetworkStreamHandler.m in Sources */, 04FC956A2EB05497007BD342 /* KBKeyButton.m in Sources */, 04FC95B22EB0B2CC007BD342 /* KBSettingView.m in Sources */, + 046131172ED06FC800A6FADF /* KBExtensionAppLauncher.m in Sources */, 049FB23B2EC4766700FAB05D /* KBFunctionTagListView.m in Sources */, 049FB23C2EC4766700FAB05D /* KBStreamOverlayView.m in Sources */, 049FB22F2EC34EB900FAB05D /* KBStreamTextView.m in Sources */, 04FC95702EB09516007BD342 /* KBFunctionView.m in Sources */, - 049FB23F2EC4B6EF00FAB05D /* KBULBridge.m in Sources */, + 049FB23F2EC4B6EF00FAB05D /* KBULBridgeNotification.m in Sources */, 04FC956D2EB054B7007BD342 /* KBKeyboardView.m in Sources */, 04FC95672EB0546C007BD342 /* KBKey.m in Sources */, A1B2C3F42EB35A9900000001 /* KBFullAccessGuideView.m in Sources */, @@ -1552,7 +1553,6 @@ A1B2C4002EB4A0A100000003 /* KBAuthManager.m in Sources */, 04A9FE132EB4D0D20020DB6D /* KBFullAccessManager.m in Sources */, A1B2C4202EB4B7A100000001 /* KBKeyboardPermissionManager.m in Sources */, - 0477BD952EBAFF4E0055D639 /* KBURLOpenBridge.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1597,7 +1597,7 @@ 04FC95D82EB1EA16007BD342 /* BaseCell.m in Sources */, 0477BDF72EBC63A80055D639 /* KBTestVC.m in Sources */, 04122F7E2EC5FC5500EF7AB3 /* KBJfPayCell.m in Sources */, - 049FB2402EC4B6EF00FAB05D /* KBULBridge.m in Sources */, + 049FB2402EC4B6EF00FAB05D /* KBULBridgeNotification.m in Sources */, 04FC95C92EB1E4C9007BD342 /* BaseNavigationController.m in Sources */, 048908DD2EBF67EB00FABA60 /* KBSearchResultVC.m in Sources */, 047C65102EBCA8DD0035E841 /* HomeRankContentVC.m in Sources */, diff --git a/keyBoard/AppDelegate.m b/keyBoard/AppDelegate.m index 415d887..6faebb3 100644 --- a/keyBoard/AppDelegate.m +++ b/keyBoard/AppDelegate.m @@ -6,29 +6,27 @@ // #import "AppDelegate.h" -#import "KBPermissionViewController.h" +//#import "KBPermissionViewController.h" #import #if !DEBUG #import #endif #import "BaseTabBarController.h" -#import "LoginViewController.h" -#import "KBLoginSheetViewController.h" -#import "AppleSignInManager.h" -#import -#import "KBULBridge.h" // Darwin 通知常量:用于通知扩展“UL已处理” +//#import "LoginViewController.h" +//#import "KBLoginSheetViewController.h" +//#import "AppleSignInManager.h" +//#import +#import "KBULBridgeNotification.h" // Darwin 通知常量:用于通知扩展“UL已处理” #import "LSTPopView.h" #import "KBLoginPopView.h" #import "IAPVerifyTransactionObj.h" #import "FGIAPManager.h" #import "KBSexSelVC.h" -#import -#import // 注意:用于判断系统已启用本输入法扩展的 bundle id 需与扩展 target 的 // PRODUCT_BUNDLE_IDENTIFIER 完全一致。 // 当前工程的 CustomKeyboard target 为 com.loveKey.nyx.CustomKeyboard -static NSString * const kKBKeyboardExtensionBundleId = @"com.loveKey.nyx.CustomKeyboard"; +//static NSString * const kKBKeyboardExtensionBundleId = @"com.loveKey.nyx.CustomKeyboard"; @implementation AppDelegate @@ -143,6 +141,10 @@ static NSString * const kKBKeyboardExtensionBundleId = @"com.loveKey.nyx.CustomK } else if ([host isEqualToString:@"settings"]) { // kbkeyboard://settings [self kb_openAppSettings]; return YES; + }else if ([host isEqualToString:@"recharge"]) { // kbkeyboard://settings +// [self kb_openAppSettings]; + [KBHUD showInfo:@"去充值"]; + return YES; } return NO; } @@ -244,26 +246,27 @@ static NSString * const kKBKeyboardExtensionBundleId = @"com.loveKey.nyx.CustomK // [PublicObj saveNetReachability:@"wwan"]; }else{ // [PublicObj saveNetReachability:@"unknown"]; + } }]; } -static BOOL KBIsKeyboardEnabled(void) { - for (UITextInputMode *mode in [UITextInputMode activeInputModes]) { - NSString *identifier = nil; - @try { - identifier = [mode valueForKey:@"identifier"]; // not a public API - } @catch (__unused NSException *e) { - identifier = nil; - } - if ([identifier isKindOfClass:[NSString class]] && - [identifier rangeOfString:kKBKeyboardExtensionBundleId].location != NSNotFound) { - return YES; - } - } - return NO; -} +//static BOOL KBIsKeyboardEnabled(void) { +// for (UITextInputMode *mode in [UITextInputMode activeInputModes]) { +// NSString *identifier = nil; +// @try { +// identifier = [mode valueForKey:@"identifier"]; // not a public API +// } @catch (__unused NSException *e) { +// identifier = nil; +// } +// if ([identifier isKindOfClass:[NSString class]] && +// [identifier rangeOfString:kKBKeyboardExtensionBundleId].location != NSNotFound) { +// return YES; +// } +// } +// return NO; +//} #pragma mark - Network check & alert @@ -306,86 +309,4 @@ static BOOL KBIsKeyboardEnabled(void) { [rootVC presentViewController:alert animated:YES completion:nil]; } -///* -// 获取网络权限状态 -// */ -//- (void)networkStatus:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { -// //2.根据权限执行相应的交互 -// CTCellularData *cellularData = [[CTCellularData alloc] init]; -// /* -// 此函数会在网络权限改变时再次调用 -// */ -// cellularData.cellularDataRestrictionDidUpdateNotifier = ^(CTCellularDataRestrictedState state) { -// switch (state) { -// case kCTCellularDataRestricted: -// -// NSLog(@"Restricted"); -// //2.1权限关闭的情况下 再次请求网络数据会弹出设置网络提示 -// -// break; -// case kCTCellularDataNotRestricted: -// -// NSLog(@"NotRestricted"); -// //2.2已经开启网络权限 监听网络状态 -// [self addReachabilityManager:application didFinishLaunchingWithOptions:launchOptions]; -// break; -// case kCTCellularDataRestrictedStateUnknown: -// -// NSLog(@"Unknown"); -// -// break; -// -// default: -// break; -// } -// }; -//} -// -///** -// 实时检查当前网络状态 -// */ -//- (void)addReachabilityManager:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { -// AFNetworkReachabilityManager *afNetworkReachabilityManager = [AFNetworkReachabilityManager sharedManager]; -// -// -// [afNetworkReachabilityManager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) { -// switch (status) { -// case AFNetworkReachabilityStatusNotReachable:{ -// NSLog(@"网络不通:%@",@(status) ); -// break; -// } -// case AFNetworkReachabilityStatusReachableViaWiFi:{ -// NSLog(@"网络通过WIFI连接:%@",@(status)); -// -// [self getInfo_application:application didFinishLaunchingWithOptions:launchOptions]; -// -// break; -// } -// case AFNetworkReachabilityStatusReachableViaWWAN:{ -// NSLog(@"网络通过无线连接:%@",@(status) ); -// -// [self getInfo_application:application didFinishLaunchingWithOptions:launchOptions]; -// -// break; -// } -// default: -// break; -// } -// }]; -// -// [afNetworkReachabilityManager startMonitoring]; //开启网络监视器; -//} -// -////把以前写在- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions里面的一些初始化操作放在该方法 -//- (void)getInfo_application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { -// -//// [self.updateBusiness checkUpdateWithBothApi];//检查app更新 -// -////发送通知给APP首屏页面,让其有网络时重新请求 -// [[NSNotificationCenter defaultCenter] postNotificationName:AFNetworkingReachabilityDidChangeNotification object:nil]; -//} -// -// -// - @end