From 2f55e7bfa1cf2859aebf063fe77d9b09bbea9fb7 Mon Sep 17 00:00:00 2001 From: CodeST <694468528@qq.com> Date: Tue, 2 Dec 2025 20:33:17 +0800 Subject: [PATCH] 3 --- CustomKeyboard/Network/KBNetworkManager.m | 2 +- Shared/KBLocalizationManager.h | 22 +++-- Shared/KBLocalizationManager.m | 28 +++++-- keyBoard/AppDelegate.m | 4 +- .../Class/Home/VC/FunctionTest/KBLangTestVC.m | 5 +- keyBoard/Class/Login/M/KBUser.h | 14 +--- keyBoard/Class/Login/M/KBUser.m | 81 +------------------ keyBoard/Class/Login/VC/KBLoginVC.m | 28 ++++--- keyBoard/Class/Login/VM/KBLoginVM.m | 22 ++--- keyBoard/Class/Manager/KBUserSessionManager.m | 6 +- keyBoard/Class/Network/KBNetworkManager.m | 2 +- keyBoard/KeyBoardPrefixHeader.pch | 2 + 12 files changed, 83 insertions(+), 133 deletions(-) diff --git a/CustomKeyboard/Network/KBNetworkManager.m b/CustomKeyboard/Network/KBNetworkManager.m index e5618a0..0c2646b 100644 --- a/CustomKeyboard/Network/KBNetworkManager.m +++ b/CustomKeyboard/Network/KBNetworkManager.m @@ -27,7 +27,7 @@ NSErrorDomain const KBNetworkErrorDomain = @"com.company.keyboard.network"; _enabled = NO; // 键盘扩展默认无网络能力,需外部显式开启 _timeout = 10.0; // 默认请求头:Accept 任意类型 + 使用项目多语言管理器设置 Accept-Language - NSString *lang = [KBLocalizationManager shared].currentLanguageCode ?: @"en"; + NSString *lang = [KBLocalizationManager shared].currentLanguageCode ?: KBLanguageCodeEnglish; _defaultHeaders = @{ @"Accept": @"*/*", @"Accept-Language": lang diff --git a/Shared/KBLocalizationManager.h b/Shared/KBLocalizationManager.h index 2785d91..5d060cd 100644 --- a/Shared/KBLocalizationManager.h +++ b/Shared/KBLocalizationManager.h @@ -11,6 +11,16 @@ NS_ASSUME_NONNULL_BEGIN +/// 语言码类型(集中管理,避免在各处散落写 @"en"/@"zh-Hans") +typedef NSString *KBLanguageCode NS_EXTENSIBLE_STRING_ENUM; + +/// 项目内统一使用的语言常量 +FOUNDATION_EXPORT KBLanguageCode const KBLanguageCodeEnglish; // @"en" +FOUNDATION_EXPORT KBLanguageCode const KBLanguageCodeSimplifiedChinese; // @"zh-Hans" + +/// 默认支持的语言列表(目前为 @[KBLanguageCodeEnglish, KBLanguageCodeSimplifiedChinese]) +FOUNDATION_EXPORT NSArray *KBDefaultSupportedLanguageCodes(void); + /// 当前语言变更通知(不附带 userInfo) extern NSString * const KBLocalizationDidChangeNotification; @@ -20,18 +30,18 @@ extern NSString * const KBLocalizationDidChangeNotification; /// 单例 + (instancetype)shared; -/// 当前语言代码(如:"en"、"zh-Hans"、"ja")。 +/// 当前语言代码(如:KBLanguageCodeEnglish、KBLanguageCodeSimplifiedChinese)。 /// 默认会在受支持语言中,按系统首选语言择优匹配。 -@property (nonatomic, copy, readonly) NSString *currentLanguageCode; +@property (nonatomic, copy, readonly) KBLanguageCode currentLanguageCode; -/// 支持的语言代码列表。默认 @[@"en", @"zh-Hans"]。 +/// 支持的语言代码列表。默认 `KBDefaultSupportedLanguageCodes()`。 /// 建议在启动早期设置;或设置后再调用 `-setCurrentLanguageCode:persist:` 以刷新。 -@property (nonatomic, copy) NSArray *supportedLanguageCodes; +@property (nonatomic, copy) NSArray *supportedLanguageCodes; /// 设置当前语言。 /// @param code 语言代码 /// @param persist 是否持久化到共享钥匙串(以便 App 与扩展共享该选择) -- (void)setCurrentLanguageCode:(NSString *)code persist:(BOOL)persist; +- (void)setCurrentLanguageCode:(KBLanguageCode)code persist:(BOOL)persist; /// 清除用户选择,恢复为系统最佳匹配。 - (void)resetToSystemLanguage; @@ -45,7 +55,7 @@ extern NSString * const KBLocalizationDidChangeNotification; value:(nullable NSString *)value; /// 基于一组“偏好语言”计算最佳支持语言。 -- (NSString *)bestSupportedLanguageForPreferred:(NSArray *)preferred; +- (KBLanguageCode)bestSupportedLanguageForPreferred:(NSArray *)preferred; - (void)reloadFromSharedStorageIfNeeded; diff --git a/Shared/KBLocalizationManager.m b/Shared/KBLocalizationManager.m index 936a222..8986b2e 100644 --- a/Shared/KBLocalizationManager.m +++ b/Shared/KBLocalizationManager.m @@ -7,6 +7,20 @@ #import #import "KBConfig.h" +/// 语言常量定义 +KBLanguageCode const KBLanguageCodeEnglish = @"en"; +KBLanguageCode const KBLanguageCodeSimplifiedChinese = @"zh-Hans"; + +/// 默认支持语言列表(集中配置) +NSArray *KBDefaultSupportedLanguageCodes(void) { + static NSArray *codes; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + codes = @[KBLanguageCodeEnglish, KBLanguageCodeSimplifiedChinese]; + }); + return codes; +} + /// 语言变更通知名称 NSString * const KBLocalizationDidChangeNotification = @"KBLocalizationDidChangeNotification"; @@ -15,7 +29,7 @@ static NSString * const kKBLocService = @"com.loveKey.nyx.loc"; static NSString * const kKBLocAccount = @"lang"; // 保存 UTF8 的语言代码 @interface KBLocalizationManager () -@property (nonatomic, copy, readwrite) NSString *currentLanguageCode; // 当前语言代码 +@property (nonatomic, copy, readwrite) KBLanguageCode currentLanguageCode; // 当前语言代码 @property (nonatomic, strong) NSBundle *langBundle; // 对应语言的 .lproj 资源包 @end @@ -37,11 +51,11 @@ static inline NSMutableDictionary *KBLocBaseKCQuery(void) { static KBLocalizationManager *m; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ m = [KBLocalizationManager new]; // 默认支持语言;可在启动时由外部重置 - m.supportedLanguageCodes = @[ @"en", @"zh-Hans" ]; + m.supportedLanguageCodes = KBDefaultSupportedLanguageCodes(); // 启动读取:先取共享钥匙串,再按系统偏好回退 NSString *saved = [[self class] kc_read]; if (saved.length == 0) { - saved = [m bestSupportedLanguageForPreferred:[NSLocale preferredLanguages]] ?: @"en"; + saved = [m bestSupportedLanguageForPreferred:[NSLocale preferredLanguages]] ?: KBLanguageCodeEnglish; } [m applyLanguage:saved]; }); @@ -56,7 +70,7 @@ static inline NSMutableDictionary *KBLocBaseKCQuery(void) { for (NSString *c in supportedLanguageCodes) { if (c.length) { [set addObject:c]; } } - _supportedLanguageCodes = set.array.count ? set.array : @[ @"en" ]; + _supportedLanguageCodes = set.array.count ? (NSArray *)set.array : @[ KBLanguageCodeEnglish ]; // 若当前语言不再受支持,则按最佳匹配切回(不持久化,仅内存),并广播变更 if (self.currentLanguageCode.length && ![set containsObject:self.currentLanguageCode]) { NSString *best = [self bestSupportedLanguageForPreferred:@[self.currentLanguageCode]]; @@ -74,7 +88,7 @@ static inline NSMutableDictionary *KBLocBaseKCQuery(void) { } - (void)resetToSystemLanguage { - NSString *best = [self bestSupportedLanguageForPreferred:[NSLocale preferredLanguages]] ?: @"en"; + NSString *best = [self bestSupportedLanguageForPreferred:[NSLocale preferredLanguages]] ?: KBLanguageCodeEnglish; [self setCurrentLanguageCode:best persist:NO]; } @@ -92,7 +106,7 @@ static inline NSMutableDictionary *KBLocBaseKCQuery(void) { } - (NSString *)bestSupportedLanguageForPreferred:(NSArray *)preferred { - if (self.supportedLanguageCodes.count == 0) return @"en"; + if (self.supportedLanguageCodes.count == 0) return KBLanguageCodeEnglish; // 1) 完全匹配 for (NSString *p in preferred) { NSString *pLC = p.lowercaseString; @@ -129,7 +143,7 @@ static inline NSMutableDictionary *KBLocBaseKCQuery(void) { } } // 4) 兜底:取第一个受支持语言 - return self.supportedLanguageCodes.firstObject ?: @"en"; + return self.supportedLanguageCodes.firstObject ?: KBLanguageCodeEnglish; } #pragma mark - 内部实现 diff --git a/keyBoard/AppDelegate.m b/keyBoard/AppDelegate.m index a2e49b7..d0d5c0b 100644 --- a/keyBoard/AppDelegate.m +++ b/keyBoard/AppDelegate.m @@ -38,8 +38,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // 1. 配置内购服务 [[FGIAPManager shared] setConfigureWith:[IAPVerifyTransactionObj new]]; - /// 2:配置国际化 - [KBLocalizationManager shared].supportedLanguageCodes = @[ @"en", @"zh-Hans"]; + /// 2:配置国际化(统一使用集中管理的语言列表) + [KBLocalizationManager shared].supportedLanguageCodes = KBDefaultSupportedLanguageCodes(); /// 3 : 处理token问题 // [[KBUserSessionManager shared] bootstrapIfNeeded]; diff --git a/keyBoard/Class/Home/VC/FunctionTest/KBLangTestVC.m b/keyBoard/Class/Home/VC/FunctionTest/KBLangTestVC.m index ab2708f..7c578a5 100644 --- a/keyBoard/Class/Home/VC/FunctionTest/KBLangTestVC.m +++ b/keyBoard/Class/Home/VC/FunctionTest/KBLangTestVC.m @@ -71,7 +71,10 @@ if (!self) return; KBLocalizationManager *mgr = [KBLocalizationManager shared]; - NSString *next = [mgr.currentLanguageCode.lowercaseString hasPrefix:@"zh"] ? @"en" : @"zh-Hans"; + // 在中英文间切换:当前是中文就切到英文,否则切到简体中文 + NSString *next = [mgr.currentLanguageCode.lowercaseString hasPrefix:@"zh"] + ? KBLanguageCodeEnglish + : KBLanguageCodeSimplifiedChinese; [mgr setCurrentLanguageCode:next persist:YES]; // 语言切换后重新进入根控制器 diff --git a/keyBoard/Class/Login/M/KBUser.h b/keyBoard/Class/Login/M/KBUser.h index d78d3c9..edabd39 100644 --- a/keyBoard/Class/Login/M/KBUser.h +++ b/keyBoard/Class/Login/M/KBUser.h @@ -11,22 +11,16 @@ NS_ASSUME_NONNULL_BEGIN // 标识 @property (nonatomic, copy, nullable) NSString *userId; // id/user_id/uid -@property (nonatomic, copy, nullable) NSString *appleUserId; // 用 Apple 登录返回的 userID(可选) - // 基本信息 -@property (nonatomic, copy, nullable) NSString *nickname; -@property (nonatomic, copy, nullable) NSString *avatar; // 头像 URL +@property (nonatomic, copy, nullable) NSString *nickName; +@property (nonatomic, copy, nullable) NSString *avatarUrl; // 头像 URL @property (nonatomic, copy, nullable) NSString *gender; // 性别(后端可能返回 string/int,统一转字符串存) -@property (nonatomic, copy, nullable) NSString *mobile; @property (nonatomic, copy, nullable) NSString *email; +/// 邮箱是否验证 +@property (nonatomic, assign) BOOL emailVerified; // 会话信息 @property (nonatomic, copy, nullable) NSString *token; // token/access_token/accessToken -@property (nonatomic, copy, nullable) NSString *refreshToken; // refresh_token/refreshToken -@property (nonatomic, strong, nullable) NSDate *expiryDate; // 若后端返回过期时间,转为日期 - -/// 从后端返回(可能顶层或 data/user 嵌套)中解析用户模型。内部使用 MJExtension。 -+ (instancetype)userFromResponseObject:(id)jsonObject; @end diff --git a/keyBoard/Class/Login/M/KBUser.m b/keyBoard/Class/Login/M/KBUser.m index 5556882..ece90a4 100644 --- a/keyBoard/Class/Login/M/KBUser.m +++ b/keyBoard/Class/Login/M/KBUser.m @@ -9,89 +9,10 @@ + (NSDictionary *)mj_replacedKeyFromPropertyName { return @{ - @"userId": @[@"id", @"user_id", @"uid"], - @"appleUserId": @[@"appleUserId", @"apple_user_id", @"apple_userid", @"appleUserID"], - @"nickname": @[@"nickname", @"nick", @"name"], - @"avatar": @[@"avatar", @"avatar_url", @"head", @"headimg"], + @"userId": @[@"uid"], @"gender": @[@"gender", @"sex"], - @"mobile": @[@"mobile", @"phone"], - @"email": @[@"email"], - @"token": @[@"token", @"access_token", @"accessToken"], - @"refreshToken": @[@"refresh_token", @"refreshToken"], - @"expiryDate": @[@"expire_at", @"expireAt", @"expires_at", @"expiresAt", @"expired_at"], }; } -// 将可能是字符串/时间戳(秒/毫秒)的过期时间,转为 NSDate -- (void)setExpiryDate:(NSDate *)expiryDate { _expiryDate = expiryDate; } - -+ (instancetype)userFromResponseObject:(id)jsonObject { - if (!jsonObject) return nil; - NSDictionary *dict = nil; - if ([jsonObject isKindOfClass:NSDictionary.class]) { - dict = (NSDictionary *)jsonObject; - } else if ([jsonObject isKindOfClass:NSData.class]) { - // JSON data -> dict - id obj = [NSJSONSerialization JSONObjectWithData:(NSData *)jsonObject options:0 error:NULL]; - if ([obj isKindOfClass:NSDictionary.class]) dict = obj; - } - if (!dict) return nil; - - // 兼容多种后端包装:优先 data.user,其次 data,本身就是用户 - NSDictionary *candidate = nil; - id data = dict[@"data"]; if ([data isKindOfClass:NSDictionary.class]) { candidate = data; } - id user = [candidate objectForKey:@"user"]; if (![user isKindOfClass:NSDictionary.class]) { user = dict[@"user"]; } - NSDictionary *userDict = ([user isKindOfClass:NSDictionary.class]) ? (NSDictionary *)user : (candidate ?: dict); - - KBUser *u = [KBUser mj_objectWithKeyValues:userDict]; - - // 额外兼容:若 token 不在用户对象里,尝试从上层提取到模型上 - if (u.token.length == 0) { - NSString *t = [self pickTokenFromDictionary:dict]; - if (t.length) u.token = t; - } - - // 过期时间字段可能是字符串或时间戳,做宽松转换 - id exp = userDict[@"expire_at"] ?: userDict[@"expireAt"] ?: userDict[@"expires_at"] ?: userDict[@"expiresAt"] ?: userDict[@"expired_at"]; - if ([exp isKindOfClass:NSNumber.class]) { - // 兼容秒/毫秒(> 10^11 视为毫秒) - NSTimeInterval ts = [(NSNumber *)exp doubleValue]; - if (ts > 1e11) ts = ts / 1000.0; - u.expiryDate = [NSDate dateWithTimeIntervalSince1970:ts]; - } else if ([exp isKindOfClass:NSString.class]) { - // 尝试 ISO8601 - NSDateFormatter *fmt = [NSDateFormatter new]; - fmt.locale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"]; - fmt.dateFormat = @"yyyy-MM-dd'T'HH:mm:ssZ"; - NSDate *d = [fmt dateFromString:(NSString *)exp]; - if (!d) { - // 尝试纯秒 - NSTimeInterval ts = [(NSString *)exp doubleValue]; - if (ts > 0) d = [NSDate dateWithTimeIntervalSince1970:ts]; - } - if (d) u.expiryDate = d; - } - - return u; -} - -+ (NSString *)pickTokenFromDictionary:(NSDictionary *)dict { - if (![dict isKindOfClass:NSDictionary.class]) return nil; - NSString *(^pick)(NSDictionary *) = ^NSString *(NSDictionary *d) { - NSArray *keys = @[ @"token", @"access_token", @"accessToken" ]; - for (NSString *k in keys) { - id v = d[k]; if ([v isKindOfClass:NSString.class] && ((NSString *)v).length > 0) return v; - } - return nil; - }; - NSString *t = pick(dict); if (t.length) return t; - id data = dict[@"data"]; if ([data isKindOfClass:NSDictionary.class]) { t = pick(data); if (t.length) return t; } - id user = dict[@"user"]; if ([user isKindOfClass:NSDictionary.class]) { t = pick(user); if (t.length) return t; } - NSDictionary *d2 = dict[@"data"]; if ([d2 isKindOfClass:NSDictionary.class]) { - NSDictionary *session = d2[@"session"]; if ([session isKindOfClass:NSDictionary.class]) { t = pick(session); if (t.length) return t; } - } - return nil; -} - @end diff --git a/keyBoard/Class/Login/VC/KBLoginVC.m b/keyBoard/Class/Login/VC/KBLoginVC.m index 6c910e4..1119bb9 100644 --- a/keyBoard/Class/Login/VC/KBLoginVC.m +++ b/keyBoard/Class/Login/VC/KBLoginVC.m @@ -117,9 +117,9 @@ // 底部协议文案(单个富文本视图,内部 terms/privacy 文案可点击) [self.contentContainerView addSubview:self.agreementTextView]; [self.agreementTextView mas_makeConstraints:^(MASConstraintMaker *make) { - make.centerX.equalTo(self.contentContainerView); - make.left.greaterThanOrEqualTo(self.contentContainerView).offset(30); - make.right.lessThanOrEqualTo(self.contentContainerView).offset(-30); + // 协议文案占满容器左右 30 的留白,配合 textAlignmentCenter 实现真正水平居中 + make.left.equalTo(self.contentContainerView).offset(30); + make.right.equalTo(self.contentContainerView).offset(-30); make.bottom.equalTo(self.contentContainerView).offset(-KB_SAFE_BOTTOM - 84); }]; @@ -128,14 +128,14 @@ [self.contentContainerView addSubview:forgot]; [forgot mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.contentContainerView); - make.bottom.equalTo(self.contentContainerView).offset(-KB_SAFE_BOTTOM - 24); + make.bottom.equalTo(self.contentContainerView).offset(-KB_SAFE_BOTTOM - 10); }]; UIView *accountLine = [UIView new]; [self.contentContainerView addSubview:accountLine]; [accountLine mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.contentContainerView); - make.bottom.equalTo(forgot.mas_top).offset(-8); + make.bottom.equalTo(forgot.mas_top).offset(-2); }]; [accountLine addSubview:self.noAccountLabel]; @@ -246,7 +246,7 @@ _emailLoginButton = [UIButton buttonWithType:UIButtonTypeCustom]; [_emailLoginButton setTitle:KBLocalized(@"Continue Via Email") forState:UIControlStateNormal]; [_emailLoginButton setTitleColor:[UIColor colorWithHex:KBBlackValue] forState:UIControlStateNormal]; - _emailLoginButton.titleLabel.font = [KBFont medium:16]; + _emailLoginButton.titleLabel.font = [KBFont medium:19]; // _emailLoginButton.backgroundColor = [UIColor colorWithHex:0xF7F7F7]; _emailLoginButton.layer.cornerRadius = 10.0; _emailLoginButton.layer.masksToBounds = YES; @@ -291,10 +291,14 @@ NSString *termsText = @"terms of service"; NSString *privacyText = @"privacy policy"; + NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init]; + paragraph.alignment = NSTextAlignmentCenter; // 多行文本整体居中 + NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:fullText attributes:@{ - NSFontAttributeName : [KBFont regular:12], - NSForegroundColorAttributeName : [UIColor colorWithHex:0x717171] + NSFontAttributeName : [KBFont regular:10], + NSForegroundColorAttributeName : [UIColor colorWithHex:0x717171], + NSParagraphStyleAttributeName : paragraph }]; NSString *lowerFull = fullText.lowercaseString; @@ -332,8 +336,8 @@ if (!_noAccountLabel) { _noAccountLabel = [UILabel new]; _noAccountLabel.text = KBLocalized(@"Don't Have An Account?"); - _noAccountLabel.font = [KBFont regular:13]; - _noAccountLabel.textColor = [UIColor colorWithWhite:0.45 alpha:1.0]; + _noAccountLabel.font = [KBFont regular:10]; + _noAccountLabel.textColor = [UIColor colorWithHex:KBBlackValue]; } return _noAccountLabel; } @@ -343,7 +347,7 @@ _signUpButton = [UIButton buttonWithType:UIButtonTypeCustom]; [_signUpButton setTitle:KBLocalized(@"Sign Up") forState:UIControlStateNormal]; [_signUpButton setTitleColor:[UIColor colorWithHex:KBColorValue] forState:UIControlStateNormal]; - _signUpButton.titleLabel.font = [KBFont medium:13]; + _signUpButton.titleLabel.font = [KBFont medium:10]; [_signUpButton addTarget:self action:@selector(onTapSignUp) forControlEvents:UIControlEventTouchUpInside]; } return _signUpButton; @@ -354,7 +358,7 @@ _forgotPasswordButton = [UIButton buttonWithType:UIButtonTypeCustom]; [_forgotPasswordButton setTitle:KBLocalized(@"Forgot Password?") forState:UIControlStateNormal]; [_forgotPasswordButton setTitleColor:[UIColor colorWithHex:KBColorValue] forState:UIControlStateNormal]; - _forgotPasswordButton.titleLabel.font = [KBFont regular:13]; + _forgotPasswordButton.titleLabel.font = [KBFont regular:10]; [_forgotPasswordButton addTarget:self action:@selector(onTapForgotPassword) forControlEvents:UIControlEventTouchUpInside]; } return _forgotPasswordButton; diff --git a/keyBoard/Class/Login/VM/KBLoginVM.m b/keyBoard/Class/Login/VM/KBLoginVM.m index a19a049..2279d77 100644 --- a/keyBoard/Class/Login/VM/KBLoginVM.m +++ b/keyBoard/Class/Login/VM/KBLoginVM.m @@ -43,27 +43,29 @@ if (identityToken.length) params[@"identityToken"] = identityToken; if (authorizationCode.length) params[@"accessCode"] = authorizationCode; // 仅供后端需要时使用 if (cred.user.length) params[@"userID"] = cred.user; // 可选 - + [KBHUD show]; // 向服务端发起校验 [[KBNetworkManager shared] POST:API_APPLE_LOGIN jsonBody:params headers:nil completion:^(id _Nullable jsonOrData, NSURLResponse * _Nullable response, NSError * _Nullable error) { + [KBHUD dismiss]; if (error) { if (completion) completion(NO, error); return; } // 从返回 JSON 中提取 token(支持常见命名与层级 data/user) // 先解析用户模型(使用 MJExtension) - KBUser *user = [KBUser userFromResponseObject:jsonOrData]; + NSDictionary *dict = jsonOrData[@"data"]; + KBUser *user = [KBUser mj_objectWithKeyValues:dict]; self.currentUser = user; - NSString *token = user.token ?: [self.class tokenFromResponseObject:jsonOrData]; - if (token.length == 0) { + if (user.token.length == 0) { if (completion) completion(NO, [NSError errorWithDomain:@"KBLogin" code:-2 userInfo:@{NSLocalizedDescriptionKey: KBLocalized(@"No token returned")}]); return; } - + [[KBUserSessionManager shared] handleLoginSuccessWithUser:user]; + completion(true,nil); // 保存登录态到共享钥匙串;供 App 与扩展共享 - BOOL ok = [[KBAuthManager shared] saveAccessToken:token - refreshToken:nil - expiryDate:nil - userIdentifier:cred.user]; - if (completion) completion(ok, ok ? nil : [NSError errorWithDomain:@"KBLogin" code:-3 userInfo:@{NSLocalizedDescriptionKey: KBLocalized(@"Failed to save login state")}]); +// BOOL ok = [[KBAuthManager shared] saveAccessToken:user.token +// refreshToken:nil +// expiryDate:nil +// userIdentifier:cred.user]; +// if (completion) completion(ok, ok ? nil : [NSError errorWithDomain:@"KBLogin" code:-3 userInfo:@{NSLocalizedDescriptionKey: KBLocalized(@"Failed to save login state")}]); }]; }]; } diff --git a/keyBoard/Class/Manager/KBUserSessionManager.m b/keyBoard/Class/Manager/KBUserSessionManager.m index 4bea61e..65aa6e5 100644 --- a/keyBoard/Class/Manager/KBUserSessionManager.m +++ b/keyBoard/Class/Manager/KBUserSessionManager.m @@ -97,9 +97,9 @@ static NSString * const kKBSessionInstallFlagKey = @"KBSession.installInitialize NSString *token = user.token; if (token.length > 0) { [[KBAuthManager shared] saveAccessToken:token - refreshToken:user.refreshToken - expiryDate:user.expiryDate - userIdentifier:user.appleUserId ?: user.userId]; + refreshToken:nil + expiryDate:nil + userIdentifier:nil]; } // 再缓存用户信息,供 App/键盘使用 diff --git a/keyBoard/Class/Network/KBNetworkManager.m b/keyBoard/Class/Network/KBNetworkManager.m index 7155b98..c224320 100644 --- a/keyBoard/Class/Network/KBNetworkManager.m +++ b/keyBoard/Class/Network/KBNetworkManager.m @@ -37,7 +37,7 @@ NSErrorDomain const KBNetworkErrorDomain = @"com.company.keyboard.network"; _enabled = NO; // 键盘扩展默认无网络能力,需外部显式开启 _timeout = 10.0; // 默认请求头:Accept 任意类型 + 使用项目多语言管理器设置 Accept-Language - NSString *lang = [KBLocalizationManager shared].currentLanguageCode ?: @"en"; + NSString *lang = [KBLocalizationManager shared].currentLanguageCode ?: KBLanguageCodeEnglish; _defaultHeaders = @{ @"Accept": @"*/*", @"Accept-Language": lang diff --git a/keyBoard/KeyBoardPrefixHeader.pch b/keyBoard/KeyBoardPrefixHeader.pch index ceeb056..0c0c0eb 100644 --- a/keyBoard/KeyBoardPrefixHeader.pch +++ b/keyBoard/KeyBoardPrefixHeader.pch @@ -15,6 +15,8 @@ /// 三方 #import +#import + // 公共配置 #import "KBConfig.h" #import "KBAPI.h" // 接口路径宏(统一管理)