diff --git a/keyBoard/AppDelegate.m b/keyBoard/AppDelegate.m index 25395cb..62ef8c9 100644 --- a/keyBoard/AppDelegate.m +++ b/keyBoard/AppDelegate.m @@ -22,6 +22,9 @@ #import "IAPVerifyTransactionObj.h" #import "FGIAPManager.h" #import "KBSexSelVC.h" +#import +#import + // 注意:用于判断系统已启用本输入法扩展的 bundle id 需与扩展 target 的 // PRODUCT_BUNDLE_IDENTIFIER 完全一致。 // 当前工程的 CustomKeyboard target 为 com.loveKey.nyx.CustomKeyboard @@ -36,11 +39,11 @@ static NSString * const kKBKeyboardExtensionBundleId = @"com.loveKey.nyx.CustomK // 首次安装先进入性别选择页;点击 Skip 或确认后再进入主 TabBar BOOL hasShownSexVC = [[NSUserDefaults standardUserDefaults] boolForKey:KBSexSelectShownKey]; -// if (hasShownSexVC) { -// [self setupRootVC]; -// } else { + if (hasShownSexVC) { + [self setupRootVC]; + } else { [self setupSexSelectRootVC]; -// } + } // 主工程默认开启网络总开关(键盘扩展仍需用户允许完全访问后再行开启) [KBNetworkManager shared].enabled = YES; @@ -57,11 +60,13 @@ static NSString * const kKBKeyboardExtensionBundleId = @"com.loveKey.nyx.CustomK [Bugly startWithAppId:BuglyId config:buglyConfig]; #endif - // 键盘权限引导改由 KBGuideVC 内部负责;此处不主动弹出。 return YES; } -- (void)applicationDidBecomeActive:(UIApplication *)application{} +- (void)applicationDidBecomeActive:(UIApplication *)application{ +// [self kb_checkNetworkAndShowAlertIfNeeded]; + +} - (void)setupRootVC{ @@ -204,6 +209,9 @@ static NSString * const kKBKeyboardExtensionBundleId = @"com.loveKey.nyx.CustomK /// 使用系统网络栈发起一次简单请求(例如拉起蜂窝数据权限弹窗)。 /// 说明:只要真正访问网络,系统在需要时就会弹出“是否允许使用蜂窝数据”等提示。 - (void)kb_fireStartupNetworkRequest { +// [[KBNetworkManager shared] GET:@"https://www.apple.com" parameters:nil headers:nil completion:^(id _Nullable jsonOrData, NSURLResponse * _Nullable response, NSError * _Nullable error) { +// +// }]; NSURL *url = [NSURL URLWithString:@"https://www.apple.com"]; if (!url) { return; } @@ -252,5 +260,127 @@ static BOOL KBIsKeyboardEnabled(void) { return NO; } +#pragma mark - Network check & alert + +- (void)kb_checkNetworkAndShowAlertIfNeeded { + AFNetworkReachabilityStatus status = [AFNetworkReachabilityManager sharedManager].networkReachabilityStatus; + + // 只有在“明确不可达”时才弹 + if (status == AFNetworkReachabilityStatusNotReachable || + status == AFNetworkReachabilityStatusUnknown) { + [self kb_showNoNetworkAlert]; + } +} + +- (void)kb_showNoNetworkAlert { + UIViewController *rootVC = self.window.rootViewController; + if (!rootVC) return; + + // 防止重复弹(例如已经有一个 alert 在上面了) + if ([rootVC.presentedViewController isKindOfClass:[UIAlertController class]]) { + return; + } + + UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"网络不可用" + message:@"请在“设置”中检查本应用的无线数据权限或网络连接。" + preferredStyle:UIAlertControllerStyleAlert]; + + UIAlertAction *settings = [UIAlertAction actionWithTitle:@"去设置" + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * _Nonnull action) { + [self kb_openAppSettings]; // 你已经实现好的跳设置方法 + }]; + + UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" + style:UIAlertActionStyleCancel + handler:nil]; + + [alert addAction:settings]; + [alert addAction:cancel]; + + [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 diff --git a/keyBoard/Class/Guard/VC/KBSexSelVC.m b/keyBoard/Class/Guard/VC/KBSexSelVC.m index cfd1137..acbb516 100644 --- a/keyBoard/Class/Guard/VC/KBSexSelVC.m +++ b/keyBoard/Class/Guard/VC/KBSexSelVC.m @@ -7,6 +7,13 @@ #import "KBSexSelVC.h" +/// 性别类型 +typedef NS_ENUM(NSInteger, KBSexOption) { + KBSexOptionMale = 0, + KBSexOptionFemale, + KBSexOptionOther +}; + @interface KBSexSelVC () // 顶部区域 @@ -38,6 +45,9 @@ //@property (nonatomic, strong) CAGradientLayer *topGradientLayer; @property (nonatomic, strong) UIImageView *bgImageView; // 全屏背景图 +/// 当前选中的性别 +@property (nonatomic, assign) KBSexOption selectedSex; + @end @implementation KBSexSelVC @@ -54,6 +64,9 @@ make.edges.equalTo(self.view); }]; [self setupUI]; + + // 默认选中 Male + [self kb_updateSelection:KBSexOptionMale]; } - (void)viewDidLayoutSubviews { @@ -88,7 +101,14 @@ // 底部按钮 [self.view addSubview:self.confirmButton]; - + + // 点击卡片切换选中状态 + UITapGestureRecognizer *tapMale = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onMaleCardTapped)]; + [self.maleCardView addGestureRecognizer:tapMale]; + UITapGestureRecognizer *tapFemale = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onFemaleCardTapped)]; + [self.femaleCardView addGestureRecognizer:tapFemale]; + UITapGestureRecognizer *tapOther = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onOtherCardTapped)]; + [self.otherCardView addGestureRecognizer:tapOther]; // 跳过按钮右上角(跟随安全区) @@ -188,6 +208,21 @@ #pragma mark - Actions +/// 点击男生卡片 +- (void)onMaleCardTapped { + [self kb_updateSelection:KBSexOptionMale]; +} + +/// 点击女生卡片 +- (void)onFemaleCardTapped { + [self kb_updateSelection:KBSexOptionFemale]; +} + +/// 点击第三性别卡片 +- (void)onOtherCardTapped { + [self kb_updateSelection:KBSexOptionOther]; +} + /// 点击跳过 - (void)onSkipTapped { // 触发回调,让外部(如 AppDelegate)切换到主 TabBar @@ -208,6 +243,22 @@ [[NSUserDefaults standardUserDefaults] synchronize]; } +/// 根据当前选中的性别更新三个卡片的 UI +- (void)kb_updateSelection:(KBSexOption)sex { + self.selectedSex = sex; + + [self kb_updateCard:self.maleCardView selected:(sex == KBSexOptionMale)]; + [self kb_updateCard:self.femaleCardView selected:(sex == KBSexOptionFemale)]; + [self kb_updateCard:self.otherCardView selected:(sex == KBSexOptionOther)]; +} + +/// 统一设置卡片的选中/未选中样式 +- (void)kb_updateCard:(UIView *)card selected:(BOOL)selected { + card.layer.borderWidth = selected ? 2.0 : 0.0; + card.layer.borderColor = selected ? [UIColor colorWithHex:KBColorValue].CGColor : [UIColor clearColor].CGColor; + card.backgroundColor = selected ? [UIColor whiteColor] : [UIColor colorWithHex:0xFAFAFA]; +} + #pragma mark - Lazy UI @@ -257,10 +308,12 @@ - (UIView *)maleCardView { if (!_maleCardView) { _maleCardView = [UIView new]; - _maleCardView.backgroundColor = [UIColor whiteColor]; + // 默认未选中背景 + _maleCardView.backgroundColor = [UIColor colorWithHex:0xFAFAFA]; _maleCardView.layer.cornerRadius = 24.0; _maleCardView.layer.masksToBounds = YES; - _maleCardView.layer.borderWidth = 2.0; + // 边框样式由 kb_updateSelection 统一控制,这里先不设置宽度 + _maleCardView.layer.borderWidth = 0.0; _maleCardView.layer.borderColor = [UIColor colorWithHex:KBColorValue].CGColor; } return _maleCardView; diff --git a/keyBoard/Class/Me/V/KBMyHeaderView.m b/keyBoard/Class/Me/V/KBMyHeaderView.m index d59c75a..c7ec8b4 100644 --- a/keyBoard/Class/Me/V/KBMyHeaderView.m +++ b/keyBoard/Class/Me/V/KBMyHeaderView.m @@ -8,6 +8,8 @@ #import "UIColor+Extension.h" #import "KBPersonInfoVC.h" #import "KBMyKeyBoardVC.h" +#import "KBJfPay.h" +#import "KBVipPay.h" @interface KBMyHeaderView () @property (nonatomic, strong) UILabel *titleLabel; @@ -202,7 +204,13 @@ KBPersonInfoVC *vc = [[KBPersonInfoVC alloc] init]; [KB_CURRENT_NAV pushViewController:vc animated:true]; } -- (void)onLeftCardTap { if (self.onLeftCardTapped) { self.onLeftCardTapped(); } } -- (void)onRightCardTap { if (self.onRightCardTapped) { self.onRightCardTapped(); } } +- (void)onLeftCardTap { + KBVipPay *vc = [[KBVipPay alloc] init]; + [KB_CURRENT_NAV pushViewController:vc animated:true]; +} +- (void)onRightCardTap { + KBJfPay *vc = [[KBJfPay alloc] init]; + [KB_CURRENT_NAV pushViewController:vc animated:true]; +} @end