Files
keyboard/keyBoard/AppDelegate.m

114 lines
3.4 KiB
Mathematica
Raw Normal View History

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-29 14:17:26 +08:00
2025-10-27 20:07:37 +08:00
static NSString * const kKBKeyboardExtensionBundleId = @"com.keyBoard.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-10-27 21:55:05 +08:00
///
2025-10-27 20:07:37 +08:00
dispatch_async(dispatch_get_main_queue(), ^{
2025-10-27 21:11:28 +08:00
[self kb_presentPermissionIfNeeded];
2025-10-27 20:07:37 +08:00
});
2025-10-27 18:47:18 +08:00
return YES;
}
2025-10-27 21:11:28 +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 14:29:11 +08:00
LoginViewController *vc = [[LoginViewController 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
- (UIViewController *)kb_topMostViewController
{
UIViewController *root = self.window.rootViewController;
if (!root) return nil;
UIViewController *top = root;
while (top.presentedViewController) {
top = top.presentedViewController;
}
return top;
}
- (void)kb_presentPermissionIfNeeded
{
BOOL enabled = KBIsKeyboardEnabled();
UIViewController *top = [self kb_topMostViewController];
if (!top) return;
if ([top isKindOfClass:[KBPermissionViewController class]]) {
if (enabled) {
[top dismissViewControllerAnimated:YES completion:nil];
}
return;
}
if (!enabled) {
KBPermissionViewController *guide = [KBPermissionViewController new];
guide.modalPresentationStyle = UIModalPresentationFullScreen;
[top presentViewController:guide animated:YES completion:nil];
}
}
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