From 4e2d7d2908206b2a6437d72a2f9b74e13d3c5cb7 Mon Sep 17 00:00:00 2001 From: CodeST <694468528@qq.com> Date: Tue, 30 Dec 2025 15:27:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=83=A8=E5=88=86=E9=80=9A?= =?UTF-8?q?=E7=94=A8=E4=B8=8A=E6=8A=A5=20=E4=BF=AE=E6=94=B9bug=20=E6=9C=AA?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E5=9C=A8=E9=94=AE=E7=9B=98=E7=82=B9=E5=87=BB?= =?UTF-8?q?=E5=85=85=E5=80=BC=E8=A6=81=E5=85=88=E5=8E=BB=E8=B7=B3=E8=BD=AC?= =?UTF-8?q?=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CustomKeyboard/KeyboardViewController.m | 7 +++ Shared/KBMaiPointReporter.h | 26 +++++++++- Shared/KBMaiPointReporter.m | 50 +++++++++++++++++-- keyBoard/Class/Home/VC/HomeMainVC.m | 5 ++ keyBoard/Class/Login/VC/KBForgetPwdNewPwdVC.m | 4 +- 5 files changed, 84 insertions(+), 8 deletions(-) diff --git a/CustomKeyboard/KeyboardViewController.m b/CustomKeyboard/KeyboardViewController.m index 7d9af15..74a30bf 100644 --- a/CustomKeyboard/KeyboardViewController.m +++ b/CustomKeyboard/KeyboardViewController.m @@ -481,6 +481,13 @@ static void KBSkinInstallNotificationCallback(CFNotificationCenterRef center, } } - (void)functionView:(KBFunctionView *_Nullable)functionView didRightTapToolActionAtIndex:(NSInteger)index{ + if (!KBAuthManager.shared.isLoggedIn) { + NSString *schemeStr = [NSString stringWithFormat:@"%@://login?src=keyboard", KB_APP_SCHEME]; + NSURL *scheme = [NSURL URLWithString:schemeStr]; + // 从当前视图作为起点,通过响应链找到 UIApplication 再调起主 App + BOOL ok = [KBHostAppLauncher openHostAppURL:scheme fromResponder:self.view]; + return; + } NSString *schemeStr = [NSString stringWithFormat:@"%@://recharge?src=keyboard", KB_APP_SCHEME]; NSURL *scheme = [NSURL URLWithString:schemeStr]; // diff --git a/Shared/KBMaiPointReporter.h b/Shared/KBMaiPointReporter.h index 8567687..8b3ec19 100644 --- a/Shared/KBMaiPointReporter.h +++ b/Shared/KBMaiPointReporter.h @@ -13,12 +13,27 @@ #define KB_MAI_POINT_PATH_NEW_ACCOUNT @"/newAccount" #endif +#ifndef KB_MAI_POINT_PATH_GENERIC_DATA +#define KB_MAI_POINT_PATH_GENERIC_DATA @"/genericData" +#endif + NS_ASSUME_NONNULL_BEGIN extern NSString * const KBMaiPointErrorDomain; typedef void (^KBMaiPointReportCompletion)(BOOL success, NSError * _Nullable error); +typedef NS_ENUM(NSInteger, KBMaiPointGenericReportType) { + /// 未知/默认类型(按需扩展,具体含义以服务端约定为准) + KBMaiPointGenericReportTypeUnknown = 0, + /// 点击 + KBMaiPointGenericReportTypeClick = 1, + /// 曝光 + KBMaiPointGenericReportTypeExposure = 2, + /// 页面/进入 + KBMaiPointGenericReportTypePage = 3, +}; + /// Lightweight reporter for Mai point tracking. Safe for app + extension. @interface KBMaiPointReporter : NSObject @@ -26,9 +41,18 @@ typedef void (^KBMaiPointReportCompletion)(BOOL success, NSError * _Nullable err /// POST /newAccount with type + account. - (void)reportNewAccountWithType:(NSString *)type - account:(NSString *)account + account:(nullable NSString *)account completion:(KBMaiPointReportCompletion _Nullable)completion; +//- (void)reportGenericDataWithEvent:(NSString *)event +// account:(nullable NSString *)account +// completion:(KBMaiPointReportCompletion _Nullable)completion; + +/// POST /genericData with type + event + account. +- (void)reportGenericDataWithEventType:(KBMaiPointGenericReportType)type + account:(nullable NSString *)account + completion:(KBMaiPointReportCompletion _Nullable)completion; + /// Generic POST for future endpoints. - (void)postPath:(NSString *)path parameters:(NSDictionary *)parameters diff --git a/Shared/KBMaiPointReporter.m b/Shared/KBMaiPointReporter.m index b6f0c37..427541e 100644 --- a/Shared/KBMaiPointReporter.m +++ b/Shared/KBMaiPointReporter.m @@ -42,11 +42,16 @@ static void KBMaiPoint_DebugLogError(NSURLResponse *response, NSError *error) { return reporter; } +- (NSString *)kb_trimmedStringOrEmpty:(NSString * _Nullable)string { + NSString *value = [string isKindOfClass:[NSString class]] ? string : @""; + return [value stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] ?: @""; +} + - (void)reportNewAccountWithType:(NSString *)type - account:(NSString *)account - completion:(KBMaiPointReportCompletion)completion { - NSString *trimmedType = [type stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; - NSString *trimmedAccount = [account stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + account:(NSString * _Nullable)account + completion:(KBMaiPointReportCompletion _Nullable)completion { + NSString *trimmedType = [self kb_trimmedStringOrEmpty:type]; + NSString *trimmedAccount = [self kb_trimmedStringOrEmpty:account]; if (trimmedType.length == 0 || trimmedAccount.length == 0) { NSError *error = [NSError errorWithDomain:KBMaiPointErrorDomain code:-1 @@ -66,9 +71,44 @@ static void KBMaiPoint_DebugLogError(NSURLResponse *response, NSError *error) { [self postPath:KB_MAI_POINT_PATH_NEW_ACCOUNT parameters:params completion:completion]; } +//- (void)reportGenericDataWithEvent:(NSString *)event +// account:(NSString * _Nullable)account +// completion:(KBMaiPointReportCompletion _Nullable)completion { +// [self reportGenericDataWithType:KBMaiPointGenericReportTypeUnknown +// event:event +// account:account +// completion:completion]; +//} + +- (void)reportGenericDataWithEventType:(KBMaiPointGenericReportType)eventType + account:(nullable NSString *)account + completion:(KBMaiPointReportCompletion _Nullable)completion{ +// if ([KBUserSessionManager shared].isLoggedIn == false) { +// return; +// } + NSString *trimmedAccount = [self kb_trimmedStringOrEmpty:account]; + if (trimmedAccount.length == 0) { + NSError *error = [NSError errorWithDomain:KBMaiPointErrorDomain + code:-1 + userInfo:@{NSLocalizedDescriptionKey: @"Invalid parameter"}]; + if (completion) { + dispatch_async(dispatch_get_main_queue(), ^{ + completion(NO, error); + }); + } + return; + } + + NSDictionary *params = @{ + @"eventId": @"123", + @"account": account + }; + [self postPath:KB_MAI_POINT_PATH_GENERIC_DATA parameters:params completion:completion]; +} + - (void)postPath:(NSString *)path parameters:(NSDictionary *)parameters - completion:(KBMaiPointReportCompletion)completion { + completion:(KBMaiPointReportCompletion _Nullable)completion { if (path.length == 0 || ![parameters isKindOfClass:[NSDictionary class]]) { NSError *error = [NSError errorWithDomain:KBMaiPointErrorDomain code:-1 diff --git a/keyBoard/Class/Home/VC/HomeMainVC.m b/keyBoard/Class/Home/VC/HomeMainVC.m index 4b5e41e..9aacc63 100644 --- a/keyBoard/Class/Home/VC/HomeMainVC.m +++ b/keyBoard/Class/Home/VC/HomeMainVC.m @@ -52,6 +52,11 @@ [weakSelf.navigationController pushViewController:vc animated:true]; }; + + [[KBMaiPointReporter sharedReporter] reportGenericDataWithEventType:KBMaiPointGenericReportTypePage account:@"123" completion:^(BOOL success, NSError * _Nullable error) { + NSLog(@"==="); + }]; + // 测试groups // NSUserDefaults *sharedDefaults = [[NSUserDefaults alloc] initWithSuiteName:AppGroup]; // // 写入一个简单字符串 diff --git a/keyBoard/Class/Login/VC/KBForgetPwdNewPwdVC.m b/keyBoard/Class/Login/VC/KBForgetPwdNewPwdVC.m index db53334..8994c6b 100644 --- a/keyBoard/Class/Login/VC/KBForgetPwdNewPwdVC.m +++ b/keyBoard/Class/Login/VC/KBForgetPwdNewPwdVC.m @@ -7,7 +7,7 @@ #import "KBForgetPwdNewPwdVC.h" #import "KBLoginVM.h" -#import "KBEmailRegistVC.h" +#import "KBLoginVC.h" @interface KBForgetPwdNewPwdVC () @property (nonatomic, strong) UILabel *titleLabel; // Reset Password @@ -131,7 +131,7 @@ if (success) { UIViewController *targetVC = nil; for (UIViewController *vc in KB_CURRENT_NAV.viewControllers) { - if ([vc isKindOfClass:[KBEmailRegistVC class]]) { + if ([vc isKindOfClass:[KBLoginVC class]]) { targetVC = vc; break; }