处理键盘bug

This commit is contained in:
2026-01-30 13:46:08 +08:00
parent 3c0b7e754c
commit 2ff8a7a4af
2 changed files with 79 additions and 107 deletions

View File

@@ -855,8 +855,7 @@ static void KBSkinInstallNotificationCallback(CFNotificationCenterRef center,
if (text.length == 0) {
return;
}
NSLog(@"[Keyboard] ========== kb_sendChatText ==========");
NSLog(@"[Keyboard] chatPanelView=%p", self.chatPanelView);
NSLog(@"[KB] 发送消息: %@", text);
KBChatMessage *outgoing = [KBChatMessage userMessageWithText:text];
outgoing.avatarURL = [self kb_sharedUserAvatarURL];
@@ -869,7 +868,6 @@ static void KBSkinInstallNotificationCallback(CFNotificationCenterRef center,
}
// loading
NSLog(@"[Keyboard] 准备添加 loading 消息chatPanelView=%p", self.chatPanelView);
[self.chatPanelView kb_addLoadingAssistantMessage];
//
@@ -932,16 +930,9 @@ static void KBSkinInstallNotificationCallback(CFNotificationCenterRef center,
}
- (void)kb_reloadChatRowForMessage:(KBChatMessage *)message {
NSLog(@"[Keyboard] ========== kb_reloadChatRowForMessage ==========");
// 使 self.chatMessages tableView
UITableView *tableView = self.chatPanelView.tableView;
if (!tableView) {
NSLog(@"[Keyboard] tableView 为空,跳过");
return;
}
// tableView
NSLog(@"[Keyboard] 调用 tableView reloadData");
[tableView reloadData];
//
//
//
}
- (void)kb_requestChatAudioForText:(NSString *)text {
@@ -1011,51 +1002,40 @@ static void KBSkinInstallNotificationCallback(CFNotificationCenterRef center,
/// audioId
- (void)kb_requestChatMessageWithContent:(NSString *)content {
NSLog(@"[Keyboard] ========== kb_requestChatMessageWithContent ==========");
NSLog(@"[Keyboard] 请求内容: %@", content);
if (content.length == 0) {
NSLog(@"[Keyboard] ❌ 内容为空,移除 loading");
[self.chatPanelView kb_removeLoadingAssistantMessage];
return;
}
// AppGroup persona companionId
NSInteger companionId = [[KBVM shared] selectedCompanionIdFromAppGroup];
NSLog(@"[Keyboard] 发送聊天请求: companionId=%ld", (long)companionId);
NSLog(@"[KB] 请求聊天: companionId=%ld", (long)companionId);
__weak typeof(self) weakSelf = self;
[[KBVM shared] sendChatMessageWithContent:content
companionId:companionId
completion:^(KBChatResponse *response) {
__strong typeof(weakSelf) self = weakSelf;
if (!self) {
NSLog(@"[Keyboard] ❌ self 为空");
return;
}
NSLog(@"[Keyboard] 回调中 chatPanelView=%p", self.chatPanelView);
if (!self) return;
if (!response.success) {
NSLog(@"[Keyboard] ❌ 请求失败: %@", response.errorMessage);
NSLog(@"[KB] ❌ 请求失败: %@", response.errorMessage);
[self.chatPanelView kb_removeLoadingAssistantMessage];
[KBHUD showInfo:response.errorMessage ?: KBLocalized(@"请求失败")];
return;
}
NSLog(@"[Keyboard] ✅ 解析结果: text=%@, audioId=%@", response.text, response.audioId);
NSLog(@"[KB] ✅ 收到回复: %@", response.text);
if (response.text.length == 0) {
NSLog(@"[Keyboard] ❌ 文本为空,移除 loading");
[self.chatPanelView kb_removeLoadingAssistantMessage];
[KBHUD showInfo:KBLocalized(@"未获取到回复内容")];
return;
}
NSLog(@"[Keyboard] 准备调用 kb_addAssistantMessage, chatPanelView=%p", self.chatPanelView);
// AI
NSLog(@"[KB] 准备添加 AI 消息");
[self.chatPanelView kb_addAssistantMessage:response.text audioId:response.audioId];
NSLog(@"[Keyboard] kb_addAssistantMessage 调用完成");
NSLog(@"[KB] AI 消息添加完成");
// audioId
if (response.audioId.length > 0) {