// // AppDelegate.m // keyBoard // // Created by 张伟 on 2025/10/27. // #import "AppDelegate.h" #import "ViewController.h" #import "KBPermissionViewController.h" static NSString * const kKBKeyboardExtensionBundleId = @"com.keyBoard.CustomKeyboard"; 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; } @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; ViewController *vc = [[ViewController alloc] init]; self.window.rootViewController = vc; // Present guide if the custom keyboard is not enabled yet dispatch_async(dispatch_get_main_queue(), ^{ if (!KBIsKeyboardEnabled()) { KBPermissionViewController *guide = [KBPermissionViewController new]; guide.modalPresentationStyle = UIModalPresentationFullScreen; [self.window.rootViewController presentViewController:guide animated:YES completion:nil]; } }); return YES; } @end