From 9b43274e932b2f13a8e6bc8c07f7d0bb45070f1c Mon Sep 17 00:00:00 2001 From: CodeST <694468528@qq.com> Date: Thu, 30 Oct 2025 13:10:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=BD=91=E7=BB=9C=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E6=94=B9UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CustomKeyboard/Network/KBNetworkManager.m | 2 ++ CustomKeyboard/PrefixHeader.pch | 3 +++ keyBoard/AppDelegate.m | 2 ++ keyBoard/Class/Home/VC/HomeVC.m | 19 +++++++++---------- keyBoard/Class/Network/KBNetworkManager.m | 2 ++ keyBoard/KeyBoardPrefixHeader.pch | 3 +++ 6 files changed, 21 insertions(+), 10 deletions(-) diff --git a/CustomKeyboard/Network/KBNetworkManager.m b/CustomKeyboard/Network/KBNetworkManager.m index a1c415c..e4d993e 100644 --- a/CustomKeyboard/Network/KBNetworkManager.m +++ b/CustomKeyboard/Network/KBNetworkManager.m @@ -26,6 +26,8 @@ NSErrorDomain const KBNetworkErrorDomain = @"com.company.keyboard.network"; _enabled = NO; // 键盘扩展默认无网络能力,需外部显式开启 _timeout = 10.0; _defaultHeaders = @{ @"Accept": @"application/json" }; + // 设置基础域名,路径可相对该地址拼接 + _baseURL = [NSURL URLWithString:KB_BASE_URL]; } return self; } diff --git a/CustomKeyboard/PrefixHeader.pch b/CustomKeyboard/PrefixHeader.pch index 9beb21f..6db6558 100644 --- a/CustomKeyboard/PrefixHeader.pch +++ b/CustomKeyboard/PrefixHeader.pch @@ -17,5 +17,8 @@ #import "Masonry.h" +// 网络基地址(Mock环境) +#define KB_BASE_URL @"https://m1.apifoxmock.com/m1/5438099-5113192-default/" + #endif /* PrefixHeader_pch */ diff --git a/keyBoard/AppDelegate.m b/keyBoard/AppDelegate.m index 031d075..278d878 100644 --- a/keyBoard/AppDelegate.m +++ b/keyBoard/AppDelegate.m @@ -20,6 +20,8 @@ static NSString * const kKBKeyboardExtensionBundleId = @"com.keyBoard.CustomKeyb - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [self setupRootVC]; + // 主工程默认开启网络总开关(键盘扩展仍需用户允许完全访问后再行开启) + [KBNetworkManager shared].enabled = YES; /// 获取网络权限 [self getNetJudge]; /// Bugly diff --git a/keyBoard/Class/Home/VC/HomeVC.m b/keyBoard/Class/Home/VC/HomeVC.m index 792532f..90f79af 100644 --- a/keyBoard/Class/Home/VC/HomeVC.m +++ b/keyBoard/Class/Home/VC/HomeVC.m @@ -9,6 +9,7 @@ #import "KBGuideVC.h" @interface HomeVC () +@property (nonatomic, strong) UITextView *textView; @end @@ -17,17 +18,15 @@ - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; - // Simple demo content so the tab is distinguishable - UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero]; - label.text = @"Home"; - label.textColor = [UIColor darkTextColor]; - label.font = [UIFont systemFontOfSize:20 weight:UIFontWeightSemibold]; - [label sizeToFit]; - label.center = self.view.center; - label.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; - [self.view addSubview:label]; + CGRect frame = CGRectMake(([UIScreen mainScreen].bounds.size.width - 200)/2, 150, 200, 200); + self.textView = [[UITextView alloc] initWithFrame:frame]; + self.textView.text = @"测试"; + self.textView.layer.borderColor = [UIColor blackColor].CGColor; + self.textView.layer.borderWidth = 0.5; + [self.view addSubview:self.textView]; + [self.textView becomeFirstResponder]; - [[KBNetworkManager shared] GET:@"https://m1.apifoxmock.com/m1/5438099-5113192-default/app/config" parameters:nil headers:nil completion:^(id _Nullable jsonOrData, NSURLResponse * _Nullable response, NSError * _Nullable error) { + [[KBNetworkManager shared] GET:@"app/config" parameters:nil headers:nil completion:^(id _Nullable jsonOrData, NSURLResponse * _Nullable response, NSError * _Nullable error) { NSLog(@"===="); }]; } diff --git a/keyBoard/Class/Network/KBNetworkManager.m b/keyBoard/Class/Network/KBNetworkManager.m index a1c415c..e4d993e 100644 --- a/keyBoard/Class/Network/KBNetworkManager.m +++ b/keyBoard/Class/Network/KBNetworkManager.m @@ -26,6 +26,8 @@ NSErrorDomain const KBNetworkErrorDomain = @"com.company.keyboard.network"; _enabled = NO; // 键盘扩展默认无网络能力,需外部显式开启 _timeout = 10.0; _defaultHeaders = @{ @"Accept": @"application/json" }; + // 设置基础域名,路径可相对该地址拼接 + _baseURL = [NSURL URLWithString:KB_BASE_URL]; } return self; } diff --git a/keyBoard/KeyBoardPrefixHeader.pch b/keyBoard/KeyBoardPrefixHeader.pch index 73dca94..1477a34 100644 --- a/keyBoard/KeyBoardPrefixHeader.pch +++ b/keyBoard/KeyBoardPrefixHeader.pch @@ -29,6 +29,9 @@ //-----------------------------------------------宏定义全局----------------------------------------------------------/ +// 网络基地址(Mock环境) +#define KB_BASE_URL @"https://m1.apifoxmock.com/m1/5438099-5113192-default/" + /// UI 尺寸/设备宏 // 屏幕尺寸 #define KB_SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)