2025-10-27 18:47:18 +08:00
|
|
|
|
//
|
|
|
|
|
|
// AppDelegate.m
|
|
|
|
|
|
// keyBoard
|
|
|
|
|
|
//
|
|
|
|
|
|
// Created by 张伟 on 2025/10/27.
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
#import "AppDelegate.h"
|
2025-10-27 20:07:37 +08:00
|
|
|
|
#import "KBPermissionViewController.h"
|
2025-10-27 21:55:05 +08:00
|
|
|
|
#import <AFNetworking/AFNetworking.h>
|
|
|
|
|
|
#import <Bugly/Bugly.h>
|
2025-10-29 14:17:26 +08:00
|
|
|
|
#import "BaseTabBarController.h"
|
2025-10-30 14:29:11 +08:00
|
|
|
|
#import "LoginViewController.h"
|
2025-10-30 20:23:34 +08:00
|
|
|
|
#import "KBLoginSheetViewController.h"
|
|
|
|
|
|
#import "AppleSignInManager.h"
|
2025-11-03 13:25:41 +08:00
|
|
|
|
#import <objc/message.h>
|
2025-10-29 14:17:26 +08:00
|
|
|
|
|
2025-10-30 18:31:12 +08:00
|
|
|
|
// 注意:用于判断系统已启用本输入法扩展的 bundle id 需与扩展 target 的
|
|
|
|
|
|
// PRODUCT_BUNDLE_IDENTIFIER 完全一致。
|
|
|
|
|
|
// 当前工程的 CustomKeyboard target 为 com.keyBoardst.CustomKeyboard
|
|
|
|
|
|
static NSString * const kKBKeyboardExtensionBundleId = @"com.keyBoardst.CustomKeyboard";
|
2025-10-27 18:47:18 +08:00
|
|
|
|
|
|
|
|
|
|
@implementation AppDelegate
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
2025-10-29 14:17:26 +08:00
|
|
|
|
|
|
|
|
|
|
[self setupRootVC];
|
2025-10-30 13:10:33 +08:00
|
|
|
|
// 主工程默认开启网络总开关(键盘扩展仍需用户允许完全访问后再行开启)
|
|
|
|
|
|
[KBNetworkManager shared].enabled = YES;
|
2025-10-27 21:55:05 +08:00
|
|
|
|
/// 获取网络权限
|
|
|
|
|
|
[self getNetJudge];
|
2025-10-27 22:02:46 +08:00
|
|
|
|
/// Bugly
|
|
|
|
|
|
BuglyConfig *buglyConfig = [BuglyConfig new];
|
|
|
|
|
|
/// 设置GroupID进行配置
|
|
|
|
|
|
// buglyConfig.applicationGroupIdentifier = @"";
|
|
|
|
|
|
[Bugly startWithAppId:BuglyId config:buglyConfig];
|
2025-11-03 16:57:24 +08:00
|
|
|
|
// 键盘权限引导改由 KBGuideVC 内部负责;此处不主动弹出。
|
2025-10-27 18:47:18 +08:00
|
|
|
|
return YES;
|
|
|
|
|
|
}
|
2025-10-27 21:11:28 +08:00
|
|
|
|
|
2025-11-03 16:57:24 +08:00
|
|
|
|
- (void)applicationDidBecomeActive:(UIApplication *)application{}
|
2025-11-03 15:04:19 +08:00
|
|
|
|
|
2025-10-29 14:17:26 +08:00
|
|
|
|
|
|
|
|
|
|
- (void)setupRootVC{
|
|
|
|
|
|
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
|
|
|
|
|
|
self.window.backgroundColor = [UIColor whiteColor];
|
|
|
|
|
|
[self.window makeKeyAndVisible];
|
2025-10-30 20:23:34 +08:00
|
|
|
|
BaseTabBarController *vc = [[BaseTabBarController alloc] init];
|
2025-10-29 14:17:26 +08:00
|
|
|
|
self.window.rootViewController = vc;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-27 21:11:28 +08:00
|
|
|
|
#pragma mark - Permission presentation
|
|
|
|
|
|
|
2025-10-30 20:23:34 +08:00
|
|
|
|
|
|
|
|
|
|
#pragma mark - Deep Link
|
|
|
|
|
|
|
|
|
|
|
|
// iOS 9+
|
|
|
|
|
|
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
|
|
|
|
|
|
if (!url) return NO;
|
|
|
|
|
|
if ([[url.scheme lowercaseString] isEqualToString:@"kbkeyboard"]) {
|
2025-10-30 20:46:54 +08:00
|
|
|
|
NSString *urlHost = url.host ?: @"";
|
|
|
|
|
|
NSString *host = [urlHost lowercaseString];
|
|
|
|
|
|
if ([host isEqualToString:@"login"]) { // kbkeyboard://login
|
2025-10-30 20:23:34 +08:00
|
|
|
|
[self kb_presentLoginSheetIfNeeded];
|
|
|
|
|
|
return YES;
|
2025-10-30 20:46:54 +08:00
|
|
|
|
} else if ([host isEqualToString:@"settings"]) { // kbkeyboard://settings
|
|
|
|
|
|
[self kb_openAppSettings];
|
|
|
|
|
|
return YES;
|
2025-10-30 20:23:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
return NO;
|
|
|
|
|
|
}
|
|
|
|
|
|
return NO;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)kb_presentLoginSheetIfNeeded {
|
|
|
|
|
|
// 已登录则不提示
|
|
|
|
|
|
BOOL loggedIn = ([AppleSignInManager shared].storedUserIdentifier.length > 0);
|
|
|
|
|
|
if (loggedIn) return;
|
2025-11-03 15:04:19 +08:00
|
|
|
|
UIViewController *top = [UIViewController kb_topMostViewController];
|
2025-10-30 20:23:34 +08:00
|
|
|
|
if (!top) return;
|
|
|
|
|
|
[KBLoginSheetViewController presentIfNeededFrom:top];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-30 20:46:54 +08:00
|
|
|
|
- (void)kb_openAppSettings {
|
|
|
|
|
|
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
|
|
|
|
|
|
UIApplication *app = [UIApplication sharedApplication];
|
|
|
|
|
|
if ([app canOpenURL:url]) {
|
|
|
|
|
|
if (@available(iOS 10.0, *)) {
|
|
|
|
|
|
[app openURL:url options:@{} completionHandler:nil];
|
|
|
|
|
|
} else {
|
|
|
|
|
|
[app openURL:url];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-27 21:11:28 +08:00
|
|
|
|
- (void)kb_presentPermissionIfNeeded
|
|
|
|
|
|
{
|
2025-11-03 16:57:24 +08:00
|
|
|
|
// 该逻辑已迁移到 KBGuideVC,保留占位以兼容旧调用,但不再执行任何操作
|
2025-10-27 21:11:28 +08:00
|
|
|
|
}
|
2025-10-27 18:47:18 +08:00
|
|
|
|
|
2025-10-27 21:55:05 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-(void)getNetJudge {
|
|
|
|
|
|
AFNetworkReachabilityManager *netManager = [AFNetworkReachabilityManager sharedManager];
|
|
|
|
|
|
[netManager startMonitoring];
|
|
|
|
|
|
[netManager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status){
|
|
|
|
|
|
if (status == AFNetworkReachabilityStatusReachableViaWiFi){
|
|
|
|
|
|
// [PublicObj saveNetReachability:@"wifi"];
|
|
|
|
|
|
}else if (status == AFNetworkReachabilityStatusReachableViaWWAN){
|
|
|
|
|
|
// [PublicObj saveNetReachability:@"wwan"];
|
|
|
|
|
|
}else{
|
|
|
|
|
|
// [PublicObj saveNetReachability:@"unknown"];
|
|
|
|
|
|
}
|
|
|
|
|
|
}];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-27 22:02:46 +08:00
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-10-27 18:47:18 +08:00
|
|
|
|
@end
|