1
This commit is contained in:
@@ -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 的位置,映射到统一命名)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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 */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user