This commit is contained in:
2025-12-03 12:55:51 +08:00
parent 6be90ebb10
commit 27aa723e7d
9 changed files with 120 additions and 65 deletions

View File

@@ -8,12 +8,12 @@
#define KBAPI_h
#ifndef SUCCESS_CODE
#define SUCCESS_CODE 200
#endif
#ifndef ERROR_CODE
#define ERROR_CODE 500
#endif
//#ifndef SUCCESS_CODE
//#define SUCCESS_CODE 200
//#endif
//#ifndef ERROR_CODE
//#define ERROR_CODE 500
//#endif
// 兼容旧命名(如有使用 API_APPLE_LOGIN 的位置,映射到统一命名)

View File

@@ -112,7 +112,9 @@ static void KBAuthDarwinCallback(CFNotificationCenterRef center, void *observer,
} @catch (__unused NSException *e) { session = nil; }
}
self.current = session;
[[NSNotificationCenter defaultCenter] postNotificationName:KBAuthChangedNotification object:nil]; //
// object self +shared
[[NSNotificationCenter defaultCenter] postNotificationName:KBAuthChangedNotification
object:self];
}
- (BOOL)saveAccessToken:(NSString *)accessToken
@@ -133,7 +135,8 @@ static void KBAuthDarwinCallback(CFNotificationCenterRef center, void *observer,
if (ok) {
self.current = s;
//
[[NSNotificationCenter defaultCenter] postNotificationName:KBAuthChangedNotification object:nil];
[[NSNotificationCenter defaultCenter] postNotificationName:KBAuthChangedNotification
object:self];
// App <->
CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), (__bridge CFStringRef)kKBDarwinAuthChanged, NULL, NULL, true);
}
@@ -143,7 +146,8 @@ static void KBAuthDarwinCallback(CFNotificationCenterRef center, void *observer,
- (void)signOut {
[self keychainDelete];
self.current = nil;
[[NSNotificationCenter defaultCenter] postNotificationName:KBAuthChangedNotification object:nil];
[[NSNotificationCenter defaultCenter] postNotificationName:KBAuthChangedNotification
object:self];
CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), (__bridge CFStringRef)kKBDarwinAuthChanged, NULL, NULL, true);
}

View File

@@ -16,17 +16,59 @@
/// 服务端业务状态码(按项目实际调整)
typedef NS_ENUM(NSInteger, KBBizCode) {
/// 通用成功(通常为 200对应 SUCCESS_CODE
KBBizCodeSuccess = SUCCESS_CODE,
/// 业务成功SUCCESS(0, "ok")
KBBizCodeSuccess = 0,
/// token 失效/未登录(示例值;请按后端实际 code 修改)
KBBizCodeTokenInvalid = 40101,
/// 参数错误PARAMS_ERROR(40000, "请求参数错误")
KBBizCodeParamsError = 40000,
/// token 过期(可选;如无区分可与 KBBizCodeTokenInvalid 复用)
KBBizCodeTokenExpired = 40102,
/// 上传文件为空FILE_IS_EMPTY(40001, "上传文件为空")
KBBizCodeFileIsEmpty = 40001,
/// 账号在其他设备登录,被服务端强制下线
KBBizCodeAccountKicked = 40103,
/// 文件名错误FILE_NAME_ERROR(40002, "文件名错误")
KBBizCodeFileNameError = 40002,
/// Apple 登录失败APPLE_LOGIN_ERROR(40003, "Apple登录失败")
KBBizCodeAppleLoginError = 40003,
/// 未登录NOT_LOGIN_ERROR(40100, "未登录")
KBBizCodeNotLogin = 40100,
/// 无权限NO_AUTH_ERROR(40101, "无权限")
KBBizCodeNoAuth = 40101,
/// 未能读取到有效用户令牌TOKEN_NOT_FOUND(40102)
KBBizCodeTokenNotFound = 40102,
/// 令牌无效TOKEN_INVALID(40103)
KBBizCodeTokenInvalid = 40103,
/// 令牌已过期TOKEN_TIMEOUT(40104)
KBBizCodeTokenTimeout = 40104,
/// 令牌已被顶下线TOKEN_BE_REPLACED(40105)
KBBizCodeTokenBeReplaced = 40105,
/// 令牌已被踢下线TOKEN_KICK_OUT(40107)
KBBizCodeTokenKickOut = 40107,
/// 令牌已被冻结TOKEN_FREEZE(40108)
KBBizCodeTokenFreeze = 40108,
/// 未按照指定前缀提交令牌TOKEN_NO_PREFIX(40109)
KBBizCodeTokenNoPrefix = 40109,
/// 禁止访问FORBIDDEN_ERROR(40300, "禁止访问")
KBBizCodeForbidden = 40300,
/// 请求数据不存在NOT_FOUND_ERROR(40400, "请求数据不存在")
KBBizCodeNotFound = 40400,
/// 系统内部异常SYSTEM_ERROR(50000, "系统内部异常")
KBBizCodeSystemError = 50000,
/// 操作失败OPERATION_ERROR(50001, "操作失败")
KBBizCodeOperationError = 50001,
};
NS_ASSUME_NONNULL_BEGIN
@@ -59,4 +101,3 @@ static inline NSString *KBBizMessageFromJSONObject(id obj) {
NS_ASSUME_NONNULL_END
#endif /* KBBizCode_h */