66
This commit is contained in:
@@ -22,6 +22,9 @@
|
||||
#import "IAPVerifyTransactionObj.h"
|
||||
#import "FGIAPManager.h"
|
||||
#import "KBSexSelVC.h"
|
||||
#import <SystemConfiguration/CaptiveNetwork.h>
|
||||
#import <CoreTelephony/CTCellularData.h>
|
||||
|
||||
// 注意:用于判断系统已启用本输入法扩展的 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
|
||||
|
||||
Reference in New Issue
Block a user